这是我第一次在 C++ 中使用 lambda 函数,我需要传递一个值以在 lambda 函数体内使用:
在上面的代码中我需要传递int参数seq_msg:
void do_connect(tcp::resolver::iterator endpoint_iterator, int seq_msg)
{
boost::asio::async_connect(socket_, endpoint_iterator, [this](boost::system::error_code ec, tcp::resolver::iterator)
{
if (!ec)
{
send_message(seq_msg);
do_read_header();
}
});
}
最佳答案
我想您应该按值捕获它并进行更改:
[this]
到:
[this, seq_msg]
关于C++ 将参数传递给 lambda 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44826961/