以下是我的代码的简化版本:
#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:错误:成员函数不存在。这有什么不对?
答案 0 :(得分:1)
请参阅此处Expression Evaluator Error CXX0052,了解当您尝试在调试器上观看此错误时出现此错误的原因。
要编辑的Visual Studio属性以关闭内联函数扩展:
将“内联函数扩展”从“默认”更改为“已禁用(/ Ob0)”。
答案 1 :(得分:1)
调试器只能调用一小部分简单函数。您的示例中的函数被认为过于复杂。
另外,请检查此主题:invoking functions while debugging with Visual Studio 2005?
例如,这个:
enum Shapes {circle, rectangle};
class Circle {
public:
Shapes getType() const
{
return circle;
}
};
int main() {
Circle *sPtr1 = new Circle;
auto t = sPtr1->getType();
return 0;
}
在QuickWatch中运行良好。