【问题标题】:too few template-parameter-lists -- specialization of template method, g++ [closed]模板参数列表太少——模板方法的专门化,g++ [关闭]
【发布时间】:2014-01-29 23:37:44
【问题描述】:

将代码从 gcc 2.95.3 移植到 gcc 4.4.2 会导致新的编译时错误:

too few template-parameter-lists

下面是该代码的抽象和简化示例。错误发生在标记线上。

#include <iostream>
using namespace std;

template<class SomeType> class SomeTemplate
{
  public:
    SomeType msg;
    void Func ();
};

void SomeTemplate<long>::Func ()        //--- Error Here ---
{
    cout << "SomeType size: " << sizeof (msg) << endl;
}

int main ()
{
    SomeTemplate<long> MyType;
    MyType.Func ();
}

【问题讨论】:

  • 这里有问题吗?
  • template&lt;&gt; 似乎不见了。
  • Clang 提供了更好的信息:"template specialization requires 'template&lt;&gt;'"
  • @WhozCraig 这应该是一个答案。
  • g++-4.6 说:specializing member ‘SomeTemplate&lt;long int&gt;::Func’ requires ‘template&lt;&gt;’ syntax

标签: c++ templates gcc g++ specialization


【解决方案1】:

template <>
void SomeTemplate<long>::Func ()        
{
    cout << "SomeType size: " << sizeof (msg) << endl;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多