# re: g++的一個bug? 回復 更多評論
2006-10-13 05:36 by
我這里也差不多
#include <iostream>
using namespace std;
class A
{
public:
template <typename T>
T f(T val);
template <>
int f(int val);
};
[root@localhost soft]# g++ testtem.cpp
testtem.cpp:9: 錯誤:顯式特例化出現在非命名空間作用域 ‘class A’ 中
testtem.cpp:10: 錯誤:‘f’ 不是一個模板函數
gcc 版本 4.1.0 20060304 (Red Hat 4.1.0-3)
# re: g++的一個bug? 回復 更多評論
2007-02-11 13:56 by
According to the Standard, template specializations can only be declared in namespace scope
http://gcc.gnu.org/ml/gcc/1998-09/msg00985.html
# re: g++的一個bug?[未登錄] 回復 更多評論
2012-07-05 17:38 by
您好, 我也遇到這個問題, 但我是想要
struct A
{
template<typename T,typename T1>
void f( T val, T1 val1 );
};
template<typename T,typename T1>
void A::f( T val, T1 val1 ) const
{
std::cout << "type" << std::endl;
}
template<>
void A::f<int,typename T1>( int val, T1 val1 ) const
{
std::cout << "int" << std::endl;
}
win32 VC++ 會出現 cannot convert 1 from T1 to T1 錯誤
這種寫法該如何解決?