brave heart
April 10th, 2002, 03:38 AM
#include <iostream>
using namespace std;
class CFather{
public:
CFather() { InitInstance(); }
virtual void InitInstance(){
cout << "I am the father." << endl;
}
};
class CSon : public CFather{
public:
void InitInstance(){
cout << "I am the son." << endl;
}
};
int main()
{
CSon son;
return 0;
}
The program's output is:
I am the father.
How can I make the CFather's constructor invoke the InitInstance function defined in the CSon?
Thanks a lot!
using namespace std;
class CFather{
public:
CFather() { InitInstance(); }
virtual void InitInstance(){
cout << "I am the father." << endl;
}
};
class CSon : public CFather{
public:
void InitInstance(){
cout << "I am the son." << endl;
}
};
int main()
{
CSon son;
return 0;
}
The program's output is:
I am the father.
How can I make the CFather's constructor invoke the InitInstance function defined in the CSon?
Thanks a lot!