我正在尝试将标准std::function
与自定义重载运算符一起使用。但是std::logical_and
,在这种情况下,无法Test
通过string
参数向我的班级申请课程。
class Test {
public:
std::string value;
Test(std::string cvalue) : value(cvalue) {}
std::string operator&& (const std::string& rhs) const {
if (rhs == value) {
return "true";
}
return "false";
}
};
int main() {
Test test("hey");
std::string out = std::logical_and<std::string>()(test, "hey");
std::cout << out << std::endl;
return 0;
}
实现此目标的正确方法是什么?我的预期输出是"true"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句