Consider testing your hypotheses or resolving your questions by writing a small piece of code and checking the outcome. It's a good learning method.
Code:
#include<iostream>
using std::cout;
using std::endl;
class parent
{
public:
int x;
parent ()
{
cout << "\tThis is the parent constructor" << endl;
x = 0;
}
};
class child: public parent
{
public:
int x;
};
class sibling: public parent
{
public:
int x;
sibling ()
{
cout << "\tThis is the sibling constructor" << endl;
x = 2;
}
};
int main()
{
cout << "Instantiating the child" << endl;
child theKid;
cout << "Instantiating the sibling" << endl;;
sibling theBro;
theKid.x = 4;
cout << "Child x = " << theKid.x << endl;
cout << "Sibling x = " << theBro.x << endl;
return 0;
}
Quote:
Originally Posted by The output
Code:
Instantiating the child
This is the parent constructor
Instantiating the sibling
This is the parent constructor
This is the sibling constructor
Child x = 4
Sibling x = 2