可能重複:
Where and why do I have to put the 「template」 and 「typename」 keywords?C++模板解析錯誤
我在A
接受一個bool
模板參數類的靜態模板方法test
。當我嘗試這樣調用該函數:
x = A::test<true>(...);
解析器抱怨,因爲它對待<
作爲比運營商少。我怎樣才能告訴編譯器這是一個模板實例,而不是少於一個操作符?
可能重複:
Where and why do I have to put the 「template」 and 「typename」 keywords?C++模板解析錯誤
我在A
接受一個bool
模板參數類的靜態模板方法test
。當我嘗試這樣調用該函數:
x = A::test<true>(...);
解析器抱怨,因爲它對待<
作爲比運營商少。我怎樣才能告訴編譯器這是一個模板實例,而不是少於一個操作符?
A::template test<true>(...);
讀Where and why do I have to put the "template" and "typename" keywords?
只有'A'是一個模板參數(或其相關類型)才應該需要。 – Xeo
的template
關鍵字刪除歧義。
x = A::template test<true>(...);
'A'是模板參數嗎? – Xeo