模板参数列表太少 - 模板方法的专业化,g ++

时间:2014-01-29 23:37:45

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

将代码从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 ();
}

1 个答案:

答案 0 :(得分:1)

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