title: Calling a C++ method pointer
body: <p>I have the following sample C++ program that tucks away pointers to the methods in the class.  I am getting a compiler error when calling that method.</p>
  
  <pre><code>10     class Foo
  11     {
  12         void set_parm1(string) {}
  13         void set_parm2(string) {}
  14
  15         typedef void (Foo::*set_func_t)(string);
  16         struct Bar
  17         {
  18             string value;
  19             set_func_t set_func;
  20         };
  21
  22         map&lt;string, Bar&gt; parameter;
  23
  24         public:
  25         Foo();
  26         void set_value(string key, string value);
  27     };
  28
  29     Foo::Foo()
  30     {
  31         Bar  temp;
  32
  33         temp.value = "value1";
  34         temp.set_func = &amp;Foo::set_parm1;
  35         parameter["param1"] = temp;
  36
  37         temp.value = "value2";
  38         temp.set_func = &amp;Foo::set_parm2;
  39         parameter["param1"] = temp;
  40     }
  41
  42     void
  43     Foo::set_value(string key, string value)
  44     {
  45         Bar temp;
  46
  47         temp = parameter[key];
  48         this-&gt;*temp.set_func(value);
  49     }
  </code></pre>
  
  <p>Questions:</p>
  
  <ol>
  <li><p>Compiler error at line 48  </p>
  
  <blockquote>
    <p>./test.cc: In member function <code>'void Foo::set_value(std::string, std::string)'</code>:
    ./test.cc:51:35: error: must use <code>'.*'</code> or <code>'-&gt;*'</code> to call pointer-to-member function in <code>'temp.Foo::Bar::set_func (...)'</code>, e.g. <code>'(... -&gt;* temp.Foo::Bar::set_func) (...)'</code></p>
  </blockquote></li>
  <li><p>I want <code>set_func()</code> (which points to either <code>set_parm1()</code> or <code>set_parm2()</code>) to update the value of <code>parmX</code> in the map itself.  Is it possible for me get the addr of <code>Bar.value</code> (line 33) that is stored in the map parameter, so I can pass it to <code>set_func()</code>?  </p>
  
  <p>If no, then what is my next option, store pointer to "Bar" in the map, as opposed to copy of Bar.  Basically use <code>map&lt;string, Bar *&gt;</code>.</p></li>
  <li><p>Just sticking to STL (not using boost library), are there guidelines to saving a ptr to a struct/class vs storing the whole object in map.  (Of course this is assuming the struct/class does not have a pointer in itself, aka no deep copy needed when storing whole object).</p></li>
  </ol>
  
  <p>Thank you,<br>
  Ahmed.</p>