我這里也差不多
#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: 錯(cuò)誤:顯式特例化出現(xiàn)在非命名空間作用域 ‘class A’ 中
testtem.cpp:10: 錯(cuò)誤:‘f’ 不是一個(gè)模板函數(shù)
gcc 版本 4.1.0 20060304 (Red Hat 4.1.0-3)
According to the Standard, template specializations can only be declared in namespace scope
http://gcc.gnu.org/ml/gcc/1998-09/msg00985.html
您好, 我也遇到這個(gè)問題, 但我是想要
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++ 會(huì)出現(xiàn) cannot convert 1 from T1 to T1 錯(cuò)誤
這種寫法該如何解決?