title: What is proper syntax to overload cast operator to std::map?
body: <p>This is a C++03 question.</p>
  
  <p>In the code below, <code>class Foo</code> is a template class that contains a map from a <code>std::string</code> to a <code>T</code> member function. <code>class Bar</code> contains a member variable of type <code>Foo&lt;Bar&gt;</code>. I would like to implement a cast-to-map operator in <code>class Foo</code> so that it is "pass-through" and can be used as though it were the <em>contained</em> map, without an explicit getter, but I can't quite work out the correct syntax for the cast operator.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;map&gt;
  #include &lt;string&gt;
  
  #define FOO 1
  
  template &lt;typename T&gt;
  class Foo
  {
  public:
  #if FOO
    operator
    std::map&lt; std::string, void (T::*)( const std::string&amp;,
                                        const std::string&amp; ) &gt;&amp;()
    {
      return member_;
    }
  #else
    Foo() : member_( 42 ) {}
    operator int&amp;() { return member_; }
  #endif
  
  private:
  #if FOO
    std::map&lt; std::string, void (T::*)( const std::string&amp;,
                                        const std::string&amp; ) &gt; member_;
  #else
    int member_;
  #endif
  };
  
  class Bar
  {
  public:
  #if FOO
    void func()
    {
      fb_["a"] = &amp;Bar::abc;
    }
  #else
    void func()
    {
      std::cout &lt;&lt; fb_ &lt;&lt; std::endl;
    }
  #endif
  
    void abc( const std::string&amp; key, const std::string&amp; val )
    {
      std::cout &lt;&lt; key &lt;&lt; ": " &lt;&lt; val &lt;&lt; std::endl;
    }
  
  private:
    Foo&lt;Bar&gt; fb_;
  };
  
  int main( int argc, char* argv[] )
  {
    Bar b;
    b.func();
    return 0;
  }
  </code></pre>
  
  <p>The compile error is cryptic; I don't know what to make of it:</p>
  
  <pre><code>&gt;g++ --version
  g++ (GCC) 4.8.3 20140911 (Red Hat 4.8.3-7)
  Copyright (C) 2013 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  
  &gt;g++ -g main.cpp 
  main.cpp: In member function 'void Bar::func()':
  main.cpp:33:8: error: no match for 'operator[]' (operand types are 'Foo&lt;Bar&gt;' and 'const char [2]')
       fb_["a"] = &amp;Bar::abc;
  </code></pre>
  
  <p>You can see I've toyed with a cast-to-int operator, which works fine, but its syntax is perhaps overly simple for me to extrapolate to a cast-to-map operator.</p>
  
  <p>Can someone help with the correct syntax please?</p>