繼承有問題。我不知道我在做什麼錯。C++錯誤:不允許抽象類類型的對象:純虛函數沒有覆蓋
FigureGeometry.h
#ifndef FIGUREGEOMETRY
#define FIGUREGEOMETRY
static const float PI = 3.14159f;
class FigureGeometry
{
public:
virtual float getArea() const = 0;
virtual float getPerimeter() const = 0;
};
#endif
Circle.h
#ifndef CIRCLE
#define CIRCLE
#include "FigureGeometry.h"
class Circle:public FigureGeometry
{
float radius;
public:
Circle(float theRadius)
{
radius = theRadius;
}
float getRadius() {return radius;}
float getArea() {return getRadius() * getRadius() * PI;}
float getPerimeter() {return getRadius() * 2 * PI;}
};
#endif
,然後在main.cpp中,含有"Circle c1(5);"
行我得到的錯誤:
21 IntelliSense: object of abstract class type "Circle" is not allowed:
pure virtual function "FigureGeometry::getArea" has no overrider
pure virtual function "FigureGeometry::getPerimeter" has no overrider c:\Users\moog\Documents\Visual Studio 2012\Projects\data structures 3\data structures 3\main.cpp 9 9 data structures 3
'getArea()'和'getArea()const'是兩個不同的函數。 – 2014-11-09 05:15:56