title: Workaround for VS2010: templates and overloaded functions
body: <p>I've code that are perfect build with mingw/g++ compilers but MSVC (2010) encountered error. Problem is overloaded functions and templates. May be somebody know workaround for MSVC? If workaround not exist (proof link is diserable) it also answer.</p>
  
  <p>Code example:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  struct Function 
  {
      virtual ~Function() {}
      virtual void operator()() = 0;
  };
  
  template &lt;typename Class, typename ARG1&gt;
  struct MemberFunction1 : public Function
  {
      typedef void (Class::*MEM_FUNC)(ARG1);
      explicit MemberFunction1(Class * obj, MEM_FUNC func, ARG1 arg1) :  m_object(obj), m_func(func), m_arg1(arg1) {}
  
      virtual void operator()()
      {
          (m_object-&gt;*m_func)(m_arg1);
      }
  
      Class *  m_object;
      MEM_FUNC m_func;    
      ARG1     m_arg1;
  };
  
  struct FunctionStorage
  {
      explicit FunctionStorage(Function * func) : m_func(func) {}
  
      virtual ~FunctionStorage()
      {
          if (m_func)
          {
              delete m_func;
              m_func = 0;
          }
      }
  
      void call() { (*m_func)(); }
      Function * m_func;
  };
  
  struct MemberFunction : public FunctionStorage
  {
      template &lt;typename Class, typename ARG1&gt;
      MemberFunction(Class * obj, void (Class::*func)(ARG1), ARG1 arg1) : FunctionStorage(new MemberFunction1&lt;Class, ARG1&gt;(obj, func, arg1)) {}
  };
  
  
  class Foo 
  {
  public:
      void funcWithParam(int value)
      {
          std::cout &lt;&lt; "foo::funcWithParam(" &lt;&lt; value &lt;&lt; ")\n";
      }
      void funcWithParam(const char * msg)
      {
          std::cout &lt;&lt; "foo::funcWithParam(" &lt;&lt; msg &lt;&lt; ")\n";
      }
  };
  
  int main()
  {
      Foo f;    
      MemberFunction(&amp;f, &amp;Foo::funcWithParam, 5).call(); // problem here, if remove one of funcWithParam (stay only 1 function, no overload) all will be ok
      MemberFunction(&amp;f, &amp;Foo::funcWithParam, "hello").call(); 
      return 0;
  }
  </code></pre>
  
  <p>My output:</p>
  
  <pre><code>main.cpp(65): error C2660: 'MemberFunction::MemberFunction' : function does not take 3 arguments
  main.cpp(65): error C2228: left of '.call' must have class/struct/union
  main.cpp(66): error C2660: 'MemberFunction::MemberFunction' : function does not take 3 arguments
  main.cpp(66): error C2228: left of '.call' must have class/struct/union
  </code></pre>
  
  <p><a href="http://ideone.com/ECi7e" rel="nofollow">Here is ideone</a> build result.</p>