2011-07-27 31 views
0

我很新的模板元編程,並不能找到我的思維錯誤在這種方法:專營函數模板結果

template <typename T> 
    typename T::ReturnType Query(const std::string& Str); 

template <> 
ResultTypeRowCount Query(const std::string& Str) { return this->queryRowCount(Str); } 

ResultTypeRowCount實現與名稱返回類型

三江源閱讀公衆的typedef

+0

你能詳細說明你在這裏做什麼嗎? C++不會推導出函數的返回類型,因爲僅僅給出參數就沒有辦法推導出'T'。你在這裏預期的行爲是什麼? – templatetypedef

+0

我想歸檔某種返回類型的重載。由於我無法將模板聲明爲虛擬函數,因此我無法將函數映射到專業化。 – Mythli

回答

2

它應該是:

template <> 
ResultTypeRowCount::ReturnType Query<ResultTypeRowCount>(const std::string& Str) { return this->queryRowCount(Str); } 
1

Specializi ng你的模板應該遵循這種模式:

template<typename T> 
    void foo() { 
    } 

template<> 
    void foo<int>() { 
    } 
+0

正確的想法,除了你的回答掩蓋了提問者錯誤的確切事物之一。 – Novelocrat

+0

這是真的。我只評論了模板元編程概念被忽略,這似乎是最相關的。學會釣魚,而不是。 –