我試圖編譯下面的代碼:C++編譯器將模板語法如「<」操作者
struct A {
template<int N> static void a() {}
};
template<> void A::a<5>() {}
template<class T>
struct B {
static void b() {
T::a<5>();
}
};
void test() {
A::a<5>();
B<A>::b();
}
和編譯器在T::a<5>
解釋<
作爲操作<
,導致錯誤:
invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator<’
有沒有什麼辦法顯式實例化T::a<5>
沒有編譯錯誤? 謝謝。
gcc版本4.5.1 20100924(紅帽4.5.1-4)(GCC)
[template disambiguator]的可能重複(http://stackoverflow.com/questions/4077110/template-disambiguator) – iammilind