//==============================================================================
// Include Files
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#include <iostream>
#include <string>
//==============================================================================
// Name Space
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
using namespace std;
//==============================================================================
// Class
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
class ParentClass {
//--------------------------------------------------------------------------
public:
ParentClass() { // Constructor
//this->SetName(); // ERROR!!
}
~ParentClass() { // Destructor
}
virtual void ShowName(void) {
cout<<"The name is "<<this->name<<endl;
}
//--------------------------------------------------------------------------
protected:
virtual void SetName(void)=0;
string name;
//--------------------------------------------------------------------------
};
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
class ChildClassA:public ParentClass {
//--------------------------------------------------------------------------
public:
ChildClassA() { // Constructor
cout<<"ChildClassA be created."<<endl;
//this->SetName();
}
~ChildClassA() { // Destructor
cout<<"ChildClassA be killed."<<endl;
}
//--------------------------------------------------------------------------
protected:
virtual void SetName(void) {
this->name = "Tom";
}
//--------------------------------------------------------------------------
};
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
class ChildClassB:public ParentClass {
//--------------------------------------------------------------------------
public:
ChildClassB() { // Constructor
cout<<"ChildClassB be created."<<endl;
//this->SetName();
}
~ChildClassB() { // Destructor
cout<<"ChildClassB be killed."<<endl;
}
//--------------------------------------------------------------------------
protected:
virtual void SetName(void) {
this->name = "Sam";
}
//--------------------------------------------------------------------------
};
//==============================================================================
// Main
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
int main() {
//--------------------------------------------------------------------------
ChildClassA *child_a;
child_a = new ChildClassA();
child_a->ShowName();
delete child_a;
//--------------------------------------------------------------------------
ChildClassB *child_b;
child_b = new ChildClassB();
child_b->ShowName();
delete child_b;
//--------------------------------------------------------------------------
return (0);
}
//==============================================================================