|
Go4Expert Founder
|
![]() |
| 6Sep2007,09:51 | #2 |
|
Quote:
Originally Posted by Jaya |
|
Team Leader
|
![]() |
| 6Sep2007,11:27 | #3 |
|
Can a bear shitted?
|
|
Light Poster
|
|
| 6Sep2007,11:57 | #4 |
|
Can a constructor of a class be inherited ? can u please explain in detail
|
|
Go4Expert Founder
|
![]() |
| 6Sep2007,15:23 | #5 |
|
Quote:
Originally Posted by Jaya |
|
Team Leader
|
![]() |
| 6Sep2007,20:37 | #6 |
|
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 |


