title: Google Test crashing when trying to unit test a function which calls a function member of an abstract class
body: <p>I have a class with a member that is an abstract class pointer. Upon instantiation, that is loaded with a pointer to a dynamic object which is a derived class of that abstract class. Because I don't necessarily know which derived class it is, I have to work through the abstract class pointer to access the functions of that class that are overridden from the abstract class. My class which uses the abstract class pointer compiles fine, but now I'm trying to unit test it with Google Test and it's giving me two issues.</p>
  
  <p>1) In my code, the upcast is implicit, but Google Test insists that it isn't possible to cast from Derived* to Base*.</p>
  
  <pre><code>basePtr = getDerivedPtr(derivedID);
  </code></pre>
  
  <p>To get this to pass, I had to change it to</p>
  
  <pre><code>basePtr = reinterpret_cast&lt;Base*&gt;(getDerivedPtr(derivedID));
  </code></pre>
  
  <p>2) Now, when I try to add a call to my class function that uses this pointer in my Google Test test it crashes with an error 134 "free(): invalid size" and backtrace information. There's only one line in that function currently:</p>
  
  <pre><code>myData = basePtr-&gt;getData();
  </code></pre>
  
  <p>Do I have bad syntax? Is there something I'm missing?</p>
  
  <p>Edit: This is the minimal reproducible example:</p>
  
  <pre><code>class Base
  {
  public:
      Base() {}
      ~Base() {}
      virtual MOCK_METHOD0(getData, float());
  };
  
  class Derived : public Base
  {
  public:
      Derived() {}
      ~Derived() {}
      MOCK_METHOD0(getData, float());
  };
  
  class ClassManager
  {
  public:
      MOCK_METHOD1(getDerivedPtr, Derived*(const int derivedID));
  }
  
  class MyClass
  {
  private:
      MyClass(ClassManager&amp; argClassManager);
  public:
      void readData();
  protected:
      Base* basePtr;
      float myData;
  }
  
  MyClass::MyClass(ClassManager&amp; argClassManager) : basePtr(0)
  {
      basePtr = argClassManager.getDerivedPtr(derivedID);
  }
  
  void MyClass::readData()
  {
      myData = basePtr-&gt;getData();
  }
  
  class MyClassFixture : public ::testing::Test {
  
      ClassManager argClassManager;
  
      MyClassFixture() :
          argClassManager()
  
      {}
  
  };
  
  TEST_F(MyClassFixture, ReadData)
  {
      MyClass mC(argClassManager);
      mC.readData();
  }
  </code></pre>