dev/cpp/figure/figure.cpp

38 lines
488 B
C++
Raw Normal View History

2014-07-04 18:52:30 +04:00
#include <iostream>
using namespace std;
class Figure {
public:
void draw () {
cout << "Figure:draw () called" << endl;
}
};
class Circle : public Figure {
public:
void draw () {
cout << "Circle:draw () called" << endl;
}
};
class ColorCircle : public Circle {
public:
void draw () {
cout << "ColorCircle:draw () called" << endl;
}
};
int main () {
Figure *fig = new ColorCircle ();
fig->draw ();
Circle fig2 = *(Circle*)fig;
fig2.draw ();
return 0;
}