Search code examples
c++debugginginheritancevirtual-functionspure-virtual

VC++ debugger - evaluating a virtual function, CXX0052: Error: member function not present


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?


Solution

  • 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)".