<分区>
在使用模板和仿函数(未出现在这个问题中)时,我最终遇到了以下简化的问题。
以下代码(也可用 here )
class A {
public:
template <class T>
bool isGood(int in) const {
const T f;
return in < f.value();
}
};
class B {
public:
int value() const {return 10;}
};
template <class T>
bool tryEvaluator(T& evaluator, int value) {
return evaluator.isGood<B>(value);
}
int main( int argc, const char* argv[] ) {
const A evaluator;
evaluator.isGood<B>(20); //Seemingly no problem here
tryEvaluator(evaluator,20);
return 0;
}
产生一个错误
main.cpp:18:34: error: expected primary-expression before ‘>’ token
return evaluator.isGood<B>(value);
^
是否可以执行我想做的事情?我需要添加一些关键字吗?
还有,附带问题,我应该如何更好地重命名我的问题?