Hey thanks
I did not want to look at the results but what I was trying to do but it didn’t work was to create a member function called set to initialize the variables
int set(int p1, int p2)
{return {m_p1, m_p2};}
and then in the main (){
IntPair p0{set(5,10)}; //to initialize p0 to {5,10}
p0.print5(); //to print the pair : (5,10)
My initialization did not work but this is how I did it for the struct. I called the function to initialize the structure. For structures the function is outside the structure as for the class I created a member function inside the class complex.
This reading assignment did not include how to initialize using a struct. That is a new concept. How would you do it by creating a member function and then use it to initialize the new class?
I also thought of doing it this way when I got to main.
IntPair p0{}; //to initialize p0 to {0.0}
p0.set(5,10); // to re-initialize p0
p0.print5(); //to print the pair : (5,10)
The problem I am having is using a member function
// Well I found the solution and the difference was that when I declare an integer the value that was initialized would be zero(0) for some reason, but when I don’t declare it as an int value I get the correct initialization.
class IntPair
{
public:
int m_p1{};
int m_p2{};
void set(int p1, int p2)
{
m_p1 = p1; // if I say int m_p1= p1;
m_p2 = p2; // and int m_p2 = p2; then it initializes to zero() instead of the values that I input at p2.set(5.10)
Can you tell me why is that ?
I also tried using a return statement to do the initialization this way:
int set(int p1, int p2)
{ return {m_p1, m_p2}
}; // This does not work. I wonder why?
``