class BClass {
( ㄱ ):
string id;
public:
BClass(const string& s):id(s) {}
virtual void action() const { cout << id << endl; }
string getID() const { return id; }
};
class DClass1:public BClass {
string att;
public:
DClass1(const string& s1, const string& s2)
( 가 )
string getAtt() const { return att; }
void action() const
{ cout << getID() << " " << att << endl; } // (ㄴ)
};
class DClass2:public DClass1 {
int x;
public:
DClass2(const string& s1, const string& s2, int n)
( 나 )
void action() const {
cout << getID() << " " << getAtt() << " "
<< x << endl;
}
};
void f() {
DClass1* pDC1 = new DClass2("ab", "cd", 10);
BClass* pBC = pDC1;
pBC->action(); // (다)
pDC1->action(); // (라)
……
}
|
댓글