【发布时间】: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<>似乎不见了。 -
Clang 提供了更好的信息:
"template specialization requires 'template<>'" -
@WhozCraig 这应该是一个答案。
-
g++-4.6 说:
specializing member ‘SomeTemplate<long int>::Func’ requires ‘template<>’ syntax
标签: c++ templates gcc g++ specialization