VS2010 C++ variadic template example

BabelFish picture BabelFish · Jan 21, 2011 · Viewed 11.1k times · Source

I have a class template and I can't seem to figure out how to perform a Variadic Template style instantiation.

Here is the "code" so far of what I'm looking for:

template<typename _Classname, typename... Args>
class CFunctorStartExT 
{
  friend class CXXFactory;
protected:
  template<typename U>
  CFunctorStartExT(typename U& _functor, Args&... args) :
    m_Functor(_functor),
    m_args(args)
  {
  }
  virtual bool ProcessLoop(CSomeClass* pThread)
  {
    return m_Functor(pThread, m_args);
  }

protected:
  _Classname& m_Functor;
  Args... m_args;
};

Obviously this won't compile :). The idea is to create a class that can store the values passed in (if any.. it might just have _Classname/U defined) on the constructor so they can be retrieved later to pass to m_Functor in another function.

First: can Variadic Template even be done in VS2010? I am getting compile problems just with the template declaration error C2143: syntax error : missing ',' before '...' from the line template<typename _Classname, typename... Args>

Second, can what I am trying to accomplish be done? Thanks!

Answer

James McNellis picture James McNellis · Jan 21, 2011

Visual C++ 2010 does not support variadic templates.