0
我正在將C++模板庫從VC++移植到GCC。下面模板類中常規類中的模板成員函數不能用GCC進行編譯,而是使用VC++
的例子編譯罰款與VS2005
#include <iostream>
template<class T>
struct A{
struct B{
template<int n>
T foo() const{
return static_cast<T>(n)/10;
}
};
T bar() const{
B b;
return b.foo<2>();
}
};
int main(){
A<float> a;
std::cout << a.bar() << std::endl;
return 0;
}
但GCC 4.4.1我收到以下錯誤
g++ ttest.cpp -o ttest
ttest.cpp: In member function ‘T A<T>::bar() const’:
ttest.cpp:14: error: expected primary-expression before ‘)’ token
ttest.cpp: In member function ‘T A<T>::bar() const [with T = float]’:
ttest.cpp:20: instantiated from here
ttest.cpp:14: error: invalid operands of types ‘<unresolved overloaded function type>’ and ‘int’ to binary ‘operator<’
make: *** [ttest] Error 1
可能有人請向我解釋什麼是錯的。
這是否符合標準?