This is my first ever question posted on Stack Overflow, hope someone could explain it.
So basically the two classes are the same except the order of the private member variables. The output is 10 20 10 0
I cannot understand why the order of declaration affects the output.
#include <iostream>
using namespace std;
class MyClass{
public:
MyClass(int value): b(value), a(b * 2){
cout << b << " " << a << " ";
}
private:
int b;
int a;
};
class YourClass{
public:
YourClass(int value): d(value), c(d * 2){
cout << d << " " << c << " ";
}
private:
int c;
int d;
};
int main(){
MyClass obj(10);
YourClass OBJ(10);
}