gpt4 book ai didi

c++ - std::bind - 在 vi​​sual studio 中编译意外(未声明的标识符)错误

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

好吧,如果我正确理解 std::bind,我可以使用 _1 之类的参数来定义一个未给定的参数?正确的?考虑以下行:

std::function<bool(value_type, const std::string &)> 
func(std::bind(&Pred, _1, "name"));

这应该行得通,对吧?这将用于 std::find_if() 函数,因此第一个参数应该是值类型,第二个参数应该是字符串。

但是 visual studio 2010 对此提示并显示以下错误消息:

error C2065: '_1' : undeclared identifier

这很奇怪,我怎么能在 visual studio 中说“嘿,第一个参数未绑定(bind)”。 Pred 是一个以 value_type, const std::string& 作为参数的简单函数 - 返回一个 bool 值。

最佳答案

在你的情况下,你想要这个:

std::function<bool(value_type, const std::string &)> 
func(std::bind(&Pred, std::placeholders::_1, "name"));

关于c++ - std::bind - 在 vi​​sual studio 中编译意外(未声明的标识符)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15359553/

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