静态联编
#include"iostream"using namespace std;
class point
{
public:
point(double x1 = 10, double y1 = 0) :x(x1), y(y1) {}
double area() { return 0; }
private:
double x, y;
};
class circle:public point
{
public:
circle(double x, double y, double r1) :point(x, y), r(r1) {}
double area() { return 3.14*r*r; }
private:
double r;
};
int main()
{
point a(2, 2); circle c(3,3,1);
cout << a.area() << endl;
cout << c.area() << endl;
point *pc = &c, &rc = c;
cout << pc->area() << endl;
cout << rc.area() << endl;
return 0;
}