38 lines
488 B
C++
38 lines
488 B
C++
|
#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;
|
||
|
}
|