1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#include <iostream>
using namespace std;
class Superclass
{
public:
virtual void doSomething(int x, int y, int z);
};
class SubClass1 : public Superclass
{
public:
virtual void doSomething(int x1, int x2, int x3);
};
void SubClass1::doSomething(int x1, int x2, int x3)
{
cout<<"subclass1 "<<x1<<x2<<endl;
}
class SubClass2 : public Superclass
{
public:
virtual void doSomething(int e1, int e2, int e3);
};
void SubClass2::doSomething(int e1, int e2, int e3)
{
cout<<"subclass2 "<<e1<<e2<<endl;
}
void Superclass::doSomething(int x, int y, int z)
{
SubClass1 objSubClass1;
SubClass2 objSubClass2;
switch(z){
case 1:
objSubClass1.doSomething(x, y, z);
break;
case 2:
objSubClass2.doSomething(x, y, z);
break;
}
}
int main(){
int xs = 1, ys = 2, zs = 1;
Superclass sc1;
SubClass1 sub1;
SubClass2 sub2;
sc1.doSomething(xs,ys,zs);
cin.get();
return 0;
}
|