title: How to use gmock MOCK_METHOD for overloaded operators?
body: <p>I am new to googlemock (and StackOverflow). I got a problem when using <code>MOCK_METHODn</code> in googlemock and I believe this function is widely used. Here is what I did.</p>
  <p>I have an abstract class <code>Foo</code> with virtual overloaded <code>operator[]</code>:</p>
  <pre><code>class Foo{
  public:
        virtual ~Foo(){};
        virtual int operator [] (int index) = 0;
  }
  </code></pre>
  <p>and I want to use googlemock to get a <code>MockFoo</code>:</p>
  <pre><code>class MockFoo: public Foo{
  public:
        MOCK_METHOD1(operator[], int(int index));  //The compiler indicates this line is incorrect
  }
  </code></pre>
  <p>However, this code gives me a compile error like this:</p>
  <pre><code>error: pasting &quot;]&quot; and &quot;_&quot; does not give a valid preprocessing token
    MOCK_METHOD1(operator[], GeneInterface&amp;(int index));
  </code></pre>
  <p>My understanding is that compiler misunderstands the <code>operator[]</code> and doesn't take it as a method name. But what is the correct way to mock the <code>operator[]</code> by using <code>MOCK_METHODn</code>? I have read the <a href="https://github.com/google/googletest/tree/master/docs" rel="noreferrer" title="googlemock documentation on github">docs</a> from googlemock but found nothing related to my question. Cound anyone help me with it?</p>
  <p>Thanks!</p>