4
我有一個頭文件下面的代碼不屬於一類:存儲類是不允許在一個明確的專業化
template<typename Foo> static const Compl<Foo,bar> *foobar (const FBTYPE &x);
template<> static const Compl<typea,bar> *foobar<typea>(const FBTYPE &x) {
return x.funcA();
}
template<> static const Compl<typeb,bar> *foobar<typeb>(const FBTYPE &x) {
return x.funcB();
}
代碼編譯剛剛與舊版本的GCC罰款,但在較新的我得到這個錯誤信息:
rsvt.h(672): error #3503: a storage class is not allowed in an explicit specialization
template<> static const Compl<typea,bar> *foobar<typea>(const FBTYPE &x) {
^
任何想法爲什麼它適用於舊版本的GCC,但沒有更新的版本?另外,我怎樣才能使它與GCC 5一起工作?
爲什麼指定你使用免費函數'靜態'? –
無論如何,這些都是模板;爲什麼'靜態'?讓他們「內聯」。 – DeiDei
我想不出任何理由在標頭中使用'static'與函數模板 –