【问题标题】:error: "explicit specialization requires 'template <>'"错误:“显式专业化需要'模板<>'”
【发布时间】:2014-09-18 22:29:53
【问题描述】:

为什么这段代码会出现这个错误?我不想做明确的专业化。这是在 Visual Studio 2012 Desktop Express 中。

错误 C2906:'T *testTemplate::popNoWait(int *)':显式 专业化需要'模板'

template <class T> class testTemplate
{
public:
  T *pop(int timeout_ms);
  T *popNoWait(int *remaining = NULL);
};

T *testTemplate<class T>::pop(int timeout_ms)
{
  return popNoWait();
}

T *testTemplate<class T>::popNoWait(int *remaining)
{
  return NULL;
}

【问题讨论】:

    标签: c++ templates


    【解决方案1】:

    这不是您从类模板中定义事物的方式。您必须首先拥有template&lt;&gt; 语法:

    template <class T>
    T *testTemplate<T>::pop(int timeout_ms)
    {
        return NULL;
    }
    
    template <class T>
    T *testTemplate<T>::popNoWait(int *remaining)
    {
        return NULL;
    }
    

    【讨论】:

      猜你喜欢
      • 2018-09-28
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-21
      • 1970-01-01
      相关资源
      最近更新 更多