質問

Here is a simplified version of my code:

#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;
}

When I tried to use debugger to watch sPtr->getType(), it says CXX0052: Error: member function not present. What's wrong here?

役に立ちましたか?

解決

See here Expression Evaluator Error CXX0052 for the explanation as to why you get this error when you tried to watch it on the debugger.

Visual Studio property to edit to turn off inline function expansion:

enter image description here

Change the "Inline function expansion" from "Default" to "Disabled (/Ob0)".

他のヒント

Only small subset of simple functions can be called by Debugger. Functions from your example are considered to be too complex.

Also, check this topic: invoking functions while debugging with Visual Studio 2005?

For example, this:

enum Shapes {circle, rectangle};

class Circle {
public:
  Shapes getType() const
  {
    return circle;
  }
};

int main() {
  Circle *sPtr1 = new Circle;
  auto t = sPtr1->getType();
  return 0;
}

works fine in QuickWatch.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top