title: Why is original method mocked by GoogleMock still getting called?
body: <p>I have been attempting to use GoogleMock to override a few specific methods in a underlying class, however I seem to be getting the base constructor, rather than the mocked object. Is there something obvious I am missing here? </p>
  
  <p>I have been following the following example:
  <a href="http://blog.divebomb.org/2011/07/my-first-c-cmake-googletest-and-googlemock/" rel="nofollow noreferrer">http://blog.divebomb.org/2011/07/my-first-c-cmake-googletest-and-googlemock/</a></p>
  
  <p>However, in my test, I am still getting my 'printf' called. Any thoughts?</p>
  
  <p>Here are the classes/header files:</p>
  
  <p><em>A.h</em>:</p>
  
  <pre><code>#pragma once
  class A
  {
  public:
      virtual void methodToOverride();
      void someConcreteMethod();
  
      int mMemberVariable;
  };
  </code></pre>
  
  <p><em>A.cpp</em>:</p>
  
  <pre><code>#include "A.h"
  
  void A::methodToOverride()
  {
      std::printf("Hello World");
  }
  
  void A::someConcreteMethod()
  {
  }
  </code></pre>
  
  <p><em>B.h</em>:</p>
  
  <pre><code>#include "A.h"
  
  class B
  {
  public:
      B(A &amp;injectedClass);
      ~B();
      void MethodToTest();
  
  private:
      A mA;
  };
  </code></pre>
  
  <p><em>B.cpp</em>:</p>
  
  <pre><code>#include "B.h"
  
  B::B(A &amp; injectedClass):mA(injectedClass)
  {
      mA.someConcreteMethod();
  }
  
  B::~B(){}
  
  void B::MethodToTest()
  {
      mA.methodToOverride();
  }
  </code></pre>
  
  <p><em>MockA.h</em>:</p>
  
  <pre><code>#include "A.h"
  #include "gmock\gmock.h"
  
  class MockA : public A
  {
  public:
      MOCK_METHOD0(methodToOverride, void());
  
  };
  </code></pre>
  
  <p>BTest.cpp:</p>
  
  <pre><code>#include "gtest/gtest.h"
  #include "MockA.h"
  #include "B.h"
  
  using ::testing::AtLeast;
  using ::testing::_;
  
  TEST(BTest, mockObject)
  {
      // Arrange
      MockA injectedMock;
      EXPECT_CALL(injectedMock, methodToOverride())
          .Times(AtLeast(1));
  
      B classUnderTest(injectedMock);
  
      // Act
      classUnderTest.MethodToTest();
  }
  </code></pre>