When I am using this code, the output changes based on the sequence of declaration of the pointers in class
#include<iostream>
using namespace std;
class myClass{
int *y,*z,*x;
public:
myClass(int a,int b,int c): x(seta(a)),y(setb(b)),z(setc(c)){}
int* seta(int a){
cout<<a;
return (new int(a));
}
int* setb(int b){
cout<<b;
return (new int(b));
}
int* setc(int c){
cout<<c;
return (new int(c));
}
};
int main(){
myClass m1(1,2,3);
return 0;
}
But when I am changing the constructor like this
myClass(int a,int b,int c){
x=seta(a);
y=setb(b);
z=setc(c);
}
Then the output is 123 irrespective of the sequence of declaration of the pointers. WHY?