gpt4 book ai didi

c++ - 错误 : expected primary-expression before ‘>’ : templated function that try to uses a template method of the class for which is templated

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:07:21 30 4
gpt4 key购买 nike

<分区>

在使用模板和仿函数(未出现在这个问题中)时,我最终遇到了以下简化的问题。

以下代码(也可用 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);
^

是否可以执行我想做的事情?我需要添加一些关键字吗?

还有,附带问题,我应该如何更好地重命名我的问题?

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com