title: Template function calling method of object of templated type
body: <p>I've got a function that I am trying to template so I can reuse it with a few different object types that all share the same method names for getting/setting information. I am still learning about templates, this is my first real attempt at using them to try and eliminate duplicate code, and I think I must be doing something illegal or incorrect.</p>
  
  <p>Here's my function, cut down to the first line of code where I am getting hung up:</p>
  
  <pre><code>//
  // Function - AddObjectToListboxAndMap: This function adds a newly created templated objected to the given map and listbox after uniquely naming it, then selects it
  //
  template &lt;typename T&gt;
  void AddObjectToListboxAndMap(ListBox^ lbObject, std::map&lt;std::string, T&gt;* tmap, T tobj)
  {
      // Uniquely name object
      tobj-&gt;SetName("new object" + boost::lexical_cast&lt;std::string&gt;(tobj-&gt;(GetGUID())));
  
      // More code here...
  }
  </code></pre>
  
  <p>I am using 4 different std::map objects:</p>
  
  <pre><code>std::map&lt;std::string, Area*&gt;* listbox_to_world_area_map;
  std::map&lt;std::string, Room*&gt;* listbox_to_area_rooms_map;
  std::map&lt;std::string, Mob*&gt;* listbox_to_area_mobs_map;
  std::map&lt;std::string, Item*&gt;* listbox_to_area_items_map;
  </code></pre>
  
  <p>And this is how I am calling the function:</p>
  
  <pre><code>// "area" previously initialized...
  Room* r = area-&gt;CreateAndAddRoom();
  AddObjectToListboxAndMap&lt;Room*&gt;(lbEditRooms, listbox_to_area_rooms_map, r);
  </code></pre>
  
  <p>When the first line in the AddObjectToListboxAndMap function is called, I get a syntax error:
  Error   1   error C2059: syntax error : '('</p>
  
  <p>After some digging, I'm feeling like the problem is the compiler not knowing how to call a method of an object of a templated type. Do I need to start messing around with function pointers to get this working, or am I missing something simple? I was hoping to just have the compiler throw an error if code elsewhere called the function and passed it an object that doesn't have a "SetName" method, but it may not work this way. Any ideas on how to properly approach this?</p>