以下代码有什么问题?
template<typename X>
struct A {
template<int N>
int foo() const {
return N;
}
};
template<typename X>
struct B {
int bar(const A<X>& v) {
return v.foo<13>();
}
};
#include <iostream>
using std::cout;
using std::endl;
int main() {
A<double> a;
B<double> b;
cout << b.bar(a) << endl;
return 0;
}
在函数B::bar
内,编译器报错:
错误:无效的操作数类型 ‘’和‘int’不能作为二进制运算符‘<’的操作数
如果A不是模板,则一切都可以正常编译。