I was trying this constructor code and got confused with how it works..
#include<iostream>
using namespace std;
class XYZ{
int a,b;
public:
XYZ(int i, int j):a(i), b(a*j){}
void show(){
cout<<a<<"\t"<<b<<"\n";
}
};
int main(){
XYZ X(2,3);
X.show();
return 0;
}
it gives the expected results but,
#include<iostream>
using namespace std;
class XYZ{
int b,a;
public:
XYZ(int i, int j):a(i), b(a*j){}
void show(){
cout<<a<<"\t"<<b<<"\n";
}
};
int main(){
XYZ X(2,3);
X.show();
return 0;
}
give unexpected result.
the only difference is int a,b
and int b,a
and how XYZ(int i, int j):a(i), b(a*j){}
works exactly?