VS2010 C ++可变参数模板示例 [英] VS2010 C++ variadic template example

查看:1723
本文介绍了VS2010 C ++可变参数模板示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类模板,我似乎不知道如何执行Variadic模板样式实例化。

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;
};

显然这不会编译:)。想法是创建一个类,它可以存储传入的值(如果有的话,它可能只有_Classname / U定义)在构造函数,所以它们可以被检索以后传递给m_Functor在另一个函数。

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.

首先:Variatis模板甚至可以在VS2010中完成吗?我得到编译问题只是与模板声明错误C2143:语法错误:缺少','前'...'模板< typename _Classname,typename ... Args>

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!

推荐答案

Visual C ++ 2010不支持可变参数模板。

Visual C++ 2010 does not support variadic templates.

这篇关于VS2010 C ++可变参数模板示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆