C++虚函数,未声明标识符
struct Shape{
virtual double area()=0;
};
class Circle:public Shape
{
public:
Circle(double r)
{
radius=r;
}
virtual double area()
{
return PI*radius*radius;
}
private:
double radius;
};
class Rectangle:public Shape
{
public:
Rectangle(double w,double h)
{
width=w;//“width”: 未声明的标识符
heigh=h;//“heigh”: 未声明的标识符
}
virtual double area()
{
return width*heigh;//“width”: 未声明的标识符“heigh”: 未声明的标识符
}
private:
double width,heigh;
};
不明白了,上面圆形类里radius也是这么写的,他没有报未声明啊?