这是我的代码的简化版本:
#include <iostream>
using namespace std;
enum Shapes {circle, rectangle};
class Shape {
public:
virtual Shapes getType() const = 0;
};
class Circle : public Shape {
public:
Shapes getType() const {
return circle;
}
};
class Rectangle : public Shape {
public:
Shapes getType() const {
return rectangle;
}
};
int main() {
Shape *sPtr = new Circle;
cout << "Circle type: " << sPtr->getType() << endl;
sPtr = new Rectangle;
cout << "Rectangle type: " << sPtr->getType() << endl;
return 0;
}
当我尝试使用调试器观看 sPtr->getType() 时,它显示 CXX0052: Error: member function not present。这里有什么问题?