一個簡單的C++文件和類TT有兩種方法。一個C++類函數
#include <map>
#include <string>
#include <iostream>
using namespace std;
class TT{
public:
TT(const string& str);
template<class T>T Read(const string& key)const;
template<class T>T Read(const string& key, const T& value)const;
};
TT::TT(const string& str){
cout<<str<<endl;
}
template<class T>T TT::Read(const string& key)const{
std::cout<<key<<std::endl;
return 1;
}
template<class T>T TT::Read(const string& key, const T& value)const{
std::cout<<key<<'\t'<<value<<std::endl;
return value;
}
int main(void){
TT tt("First");
tt.Read("Hello", 12);
return 1;
}
如果
tt.Read("Hello world!", 12);
與
tt.Read("Hello world!");
替換主()
G ++表示:
new.cc:31: error: no matching function for call to ‘TT::Read(const char [5])’
爲什麼G ++無法找到讀(const字符串&鍵)const方法?
謝謝!
它只是工作在G ++ 4.7.2 – billz
@billz,失敗對我來說:http://ideone.com/ymUPB5 –