title: Can I copy a google mock object after setting expectations?
body: <p>I want to add a utility function in my test fixture class that will return a mock with particular expectations/actions set.</p>
  
  <p>E.g.:</p>
  
  <pre><code>class MockListener: public Listener
  {
      // Google mock method.
  };
  
  class MyTest: public testing::Test
  {
  public:
      MockListener getSpecialListener()
      {
          MockListener special;
          EXPECT_CALL(special, /** Some special behaviour e.g. WillRepeatedly(Invoke( */ );
          return special;
      }
  };
  
  TEST_F(MyTest, MyTestUsingSpecialListener)
  {
      MockListener special = getSpecialListener();
  
      // Do something with special.
  }
  </code></pre>
  
  <p>Unfortunately I get:</p>
  
  <pre><code>error: use of deleted function ‘MockListener ::MockListener (MockListener &amp;&amp;)’
  </code></pre>
  
  <p>So I assume mocks can't be copied? Why, and if so is there another elegant way to get a function to manufacture a ready-made mock with expectations/actions already set?</p>
  
  <p>Obviously I can make the getSpecialListener return a MockListener&amp;, but then it would unnecessarily need to be a member of MyTest, and since only some of the tests use that particular mock (and I should only populate the mock behaviour if the test is using it) it would be less clean.</p>