平時(shí)用codeblocks,編譯時(shí)出現(xiàn)這些問(wèn)題,上網(wǎng)查結(jié)果很少,要么跳轉(zhuǎn)要英文網(wǎng)站,請(qǐng)問(wèn)這是因?yàn)檫@款軟件默認(rèn)GCC編譯而提示這樣的錯(cuò)誤(gcc的特定語(yǔ)法?)還是英文導(dǎo)致搜索結(jié)果少(我用百度)
處理這些問(wèn)題老是半天都找不到解決方法。如果前者,我應(yīng)該改大眾一些的IDE,如vc++;如果后者,我應(yīng)該改為中文?
應(yīng)該是前者吧,因?yàn)樗阉鹘Y(jié)果老是看到gcc字眼,如果在cb里設(shè)置為vc++編程是否錯(cuò)誤顯示就是vc類型了呢?
附圖_原錯(cuò)誤代碼
認(rèn)證0級(jí)講師
There are three common declaration structures related to function templates: declaring function templates, declaring specializations, and declaring instances.
template <class T, ...>
void foo();
template <>
void foo<T1, T2, ...>(); // 除非是特化含參數(shù)包的模板,否則參數(shù)列表不能為空
template void foo<T1, T2 ...>(); // 同上
The same thing happens if you replace it with operator overloading
template <class T>
std::ostream &operator<<(std::ostream &, Seqlist<T> &);
template <>
std::ostream &operator<<<int>(std::ostream &, Seqlist<int> &);
template
std::ostream &operator<<<int>(std::ostream &, Seqlist<int> &);
I think you are not specializing here, you just want to declare the template. Because you used template parameters in the function parameter list. Refer to the first way of writing.
If you don’t do too much template development, the overloading of stream’s << is actually this routine, just memorize it. Another common form is
template <class CharT, class Traits>
std::basic_ostream<CharT, Traits> &operator<<(std::basic_ostream<CharT, Traits> &, ??);
I don’t think it’s necessary to change the compiler. I can learn the syntax from the book. If you want to search, you have to search for "ostream overloading writing method" and then compare the codes. If it is a very deep template usage, the copy syntax error message search will not be able to find out the reason.
The error message the compiler gives you is very clear. Maybe you can’t read English. Don’t worry about which compiler to choose, the compiler is innocent, gcc is pretty good