Hi there. Could you tell me why this program's output is 49478692
Code:
#include <iostream>
using std::cout;
using std::endl;
class X {
public:
X() { }
X( int a ) : x( a ) { }
int getx() const { return x; }
private:
int x;
};
class Y : virtual public X {
public:
Y( int b ) : X( b ) { }
};
class Z : public Y {
public:
Z( int c ) : Y( c ) { }
};
int main()
{
Z zobj( 100 );
cout << zobj.getx() << endl;
getchar();
return 0;
}
while this program's
Code:
#include <iostream>
using std::cout;
using std::endl;
class X {
public:
X() { }
X( int a ) : x( a ) { }
int getx() const { return x; }
private:
int x;
};
class Y : public X {//<-just public,not virtual
public:
Y( int b ) : X( b ) { }
};
class Z : public Y {
public:
Z( int c ) : Y( c ) { }
};
int main()
{
Z zobj( 100 );
cout << zobj.getx() << endl;
getchar();
return 0;
}
is 100?