gpt4 book ai didi

c++ - 为什么 mem_fn 在与 smatch::str 一起使用时编译失败?

转载 作者:行者123 更新时间:2023-11-30 01:42:33 25 4
gpt4 key购买 nike

这看起来非常简单和无辜,但在调用 f(m) 时失败并显示“替换失败”页面。这是为什么?

string const input = "The quick brown fox.";
std::regex const words("[^\\s]+");

auto f = std::mem_fn(&std::smatch::str);
std::sregex_iterator i = std::sregex_iterator(input.begin(), input.end(), words);
std::smatch m = *i;

string first_word = f(m);

http://ideone.com/nsN8A1

最佳答案

因为 str takes an argument .通常它默认为 0,但 mem_fn 不会带来默认参数值,因此必须显式提供。

string first_word = f(m, 0);

http://ideone.com/nfuTFX

关于c++ - 为什么 mem_fn 在与 smatch::str 一起使用时编译失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39478802/

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