روش های غیر استاندارد و منسوخی هم وجود داره که از اساتید منسوخ ایرانی بعید نیست که به اونها هم اشاره کرده باشند!نقل قول:
آخه استادمون گفت میشه!!!(البته گفت باید تو سر خوودتون بزنید تا بشه)
داشت درمورد اینکه توی تابع draw کلاس پایه ifبزارید و از این حرفا صحبت می کرد ولی زیاد توضیح نداد!!!
نمونه:
کد:#include <iostream>
using namespace std;
enum ShapeType{
BASE = 0,
CIRCLE,
ELLIPSE
};
class shape{
public:
shape(int x1,int y1,int c1):
x(x1), y(y1), c(c1),
type(BASE)
{}
void draw(){
if (this->type == BASE)
cout << "Draw: Base Class" << endl;
else if((this->type == CIRCLE))
cout << "Draw: Circle Class" << endl;
else if((this->type == ELLIPSE))
cout << "Draw: Ellipse Class" << endl;
}
protected:
ShapeType type;
private:
int x,y;
int c;
};
class circle : public shape{
public:
circle(int x1,int y1,int c1,int r1):
shape(x1,y1,c1),
r(r1)
{
type = CIRCLE;
}
//void draw(){cout<<"draw circle:" << r << endl;}
private:
int r;
};
class ellipse : public shape{
public:
ellipse(int x1,int y1,int c1,int r1,int r2):
shape(x1,y1,c1),
rr1(r1), rr2(r2)
{
type = ELLIPSE;
}
//void draw(){cout << "draw ellipse:" << rr1 << " " << rr2 << endl;}
private:
int rr1 ,rr2;
};
int main(){
shape *shapelist[2];
shapelist[0]=new circle(1,1,9,5);
shapelist[1]=new ellipse(0,0,0,1,2);
for (unsigned int i = 0; i < 2; ++i){
shapelist[i]->draw();
}
// circle sh1(10,10,10,10);
// ellipse sh2(10,10,10,10,10);
// sh1.draw();
// sh2.draw();
return 0;
}