template 無法 link |
尚未結案
|
dadai
一般會員 發表:29 回覆:31 積分:12 註冊:2009-01-17 發送簡訊給我 |
小弟第一次使用template
遇到了一些奇怪的問題 想請前輩們指導一下 @@ 以下是我的template的寫法 TestTemplate.h [code cpp] class TestTemplate { public: static template }; [/code] TestTemplate.cpp [code cpp] template { return Value; } [/code] 以下是測試用的程式碼 [code cpp] void __fastcall TTestForm::Button1Click(TObject *Sender) { ShowMessage( IntToStr(TestTemplate::ReturnValue(100)) ); [/code]ShowMessage( FloatToStr(TestTemplate::ReturnValue(3.1416)) ); ShowMessage( TestTemplate::ReturnValue(L"Test") ); } build沒問題 但是 link 出現下列錯誤訊息 [ILINK32 Error] Error: Unresolved external 'int __fastcall TestTemplate::ReturnValue [ILINK32 Error] Error: Unresolved external 'double __fastcall TestTemplate::ReturnValue [ILINK32 Error] Error: Unresolved external 'const wchar_t * __fastcall TestTemplate::ReturnValue 請問是我有忽略什麼東西嗎 @@ 或是我的觀念不正確? |
dadai
一般會員 發表:29 回覆:31 積分:12 註冊:2009-01-17 發送簡訊給我 |
自問自答
改用下列方式就可以了 TestTemplate.h [code cpp] class TestTemplate { public: template static T __fastcall ReturnValue(const T value) { return value; } }; [/code] 看來小弟對於 C 的 template 以及一些基本概念還不甚清楚 還有很多要加強的地方...Orz 小弟告退 ===================引 用 dadai 文 章=================== 小弟第一次使用template 遇到了一些奇怪的問題 想請前輩們指導一下 @@ 以下是我的template的寫法 TestTemplate.h [code cpp] class TestTemplate { public: static template }; [/code] TestTemplate.cpp [code cpp] template { return Value; } [/code] 以下是測試用的程式碼 [code cpp] void __fastcall TTestForm::Button1Click(TObject *Sender) { ShowMessage( IntToStr(TestTemplate::ReturnValue(100)) ); [/code]ShowMessage( FloatToStr(TestTemplate::ReturnValue(3.1416)) ); ShowMessage( TestTemplate::ReturnValue(L"Test") ); } build沒問題 但是 link 出現下列錯誤訊息 [ILINK32 Error] Error: Unresolved external 'int __fastcall TestTemplate::ReturnValue [ILINK32 Error] Error: Unresolved external 'double __fastcall TestTemplate::ReturnValue [ILINK32 Error] Error: Unresolved external 'const wchar_t * __fastcall TestTemplate::ReturnValue 請問是我有忽略什麼東西嗎 @@ 或是我的觀念不正確? |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |