當我創建一個接受typename的函數時,我可以在沒有類的情況下創建它,但是當我嘗試將這個功能放入類中時,它會給我帶來錯誤。任何人都可以向我解釋我必須做些什麼才能讓它工作,爲什麼?工作情況類中的typename功能
例子:這是當我不把它一類
template<typename T>
bool Test(const char* _pcSection, const char* _pcKey, T& _tValue)
{
return true;
}
失敗的例子中:當我嘗試不幹了裏面的類(這樣我就可以訪問成員變量)
class CIniParser
{
public:
template<typename T>
bool GetValue(const char* _pcSection, const char* _pcKey, T& _tValue);
}
/////////////////////////
//Inside the .cpp...
template<typename T>
bool CIniParser::GetValue(const char* _pcSection, const char* _pcKey, T& _tValue)
{
//do stuff
return true;
}
任何幫助將是巨大的:)
定義內嵌在* .h – jsantander
中的方法[爲什麼模板只能在**頭文件中實現**](http://stackoverflow.com/questions/495021/why-can-templates-only-在頭文件中實現) – WhozCraig
「它給我錯誤」不是在堆棧溢出上進行通信的適當方式。 –