读书人

请教下面的静态联编例子为什么运行有异

发布时间: 2012-04-16 16:20:04 作者: rapoo

请问下面的静态联编例子为什么运行有错误,请各位告诉不吝赐教,先谢谢咯
//静态联编例子
#include<iostream.h>
class Point
{
Point(double i,double j){x=i;y=j;}
double Area() const {return 0.0;}
private:
double x,y;
};
class Rectangle:public Point
{
public:Rectangle(double i,double j,double k,double I);
double Area() const {return w*h;};
private:
double w,h;
};
Rectangle::Rectangle(double i,double j,double k,double I):Point(i,j)
{w=k;h=I;}
void fun(Point &s)
{
cout<<"Area="<<s.Area()<<endl;
}
void main()
{
Rectangle rec(3.0,5.2,15.0,25.0);
fun(rec);
}

[解决办法]
楼上的不对,你只需要在Point里面的构造函数前加Public就行了,不加的话默认是Private

读书人网 >C++

热点推荐