g++对模板特化的支持怎样?我的程序为什么在g++上编译不过呢?
我使用的是redhat linux 9自带的g++,代码如下:
//GNUCTest.cpp
#include <iostream>
class Util
{
public:
template<>
int func(int arg)
{
return arg+1;
}
};
int main (int argc, char *argv[])
{
Util util;
int arg = util.func(12);
std::cout << "hello world" << std::endl;
std::cout << arg << std::endl;
return 0;
}
vc6下没有问题.
在g++下:
g++ -c -ansi -traditional -x c++ -O2 -g -o "Debug/GNUCTest.o" "GNUCTest.cpp"
GNUCTest.cpp:7: error: invalid explicit specialization before '>' token
GNUCTest.cpp:7: error: explicit specialization in non-namespace scope `class Util'
GNUCTest.cpp:9: error: invalid member function declaration
GNUCTest.cpp: In function `int main(int, char**)':
GNUCTest.cpp:19: error: 'class Util' has no member named 'func2'
make: *** [Debug/GNUCTest.o] Error 1
那位高人能不吝赐教!3Q~