在研究一個問題的答案(基於this answer)我試圖做到以下幾點:爲什麼我不能成爲模板參數?
template <class T>
class friendly {
friend class T;
};
friendly<string> howdy;
這失敗,出現以下錯誤編譯:
error: template parameter "T" may not be used in an elaborated type specifier friend class T;
從我可以理解我的好朋友谷歌這是這樣,我不會不小心嘗試實例friendly<int>
但爲什麼編譯模板時這是一個錯誤?當使用無效類型實例化模板時(例如我寫的int f() { return T::foo(); }
)
如何交朋友和影響參數。 – TheTXI 2009-06-17 13:46:53
這是一個相關的問題:http://stackoverflow.com/questions/392120/why-cant-i-declare-a-friend-through-a-typedef – 2009-06-17 14:19:32