我在分析代码中出错的原因时遇到了一些麻烦。我的代码看起来很好,其他开发人员也说它很好:
void handle_read_headers(const boost::system::error_code& err, RESTClient::response& resp)
{
if (!err)
{
// Start reading remaining data until EOF.
boost::asio::async_read(socket_, response_,
boost::asio::transfer_at_least(1),
boost::bind(&client::handle_read_content, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred,
boost::ref(resp)));
}
}
void handle_read_content(const boost::system::error_code& ec, size_t bytes_transferred, RESTClient::response& resp)
{
if (!ec)
{
// Write all of the data that has been read so far.
std::cout << &response_;
// Continue reading remaining data until EOF.
boost::asio::async_read(socket_, response_,
boost::asio::transfer_at_least(1),
boost::bind(&client::handle_read_content, this,
boost::asio::placeholders::error));
}
}
可以在此处找到完整的源代码:http://bit.ly/1gnemqG
错误就是这个
Error 1 error C2825: 'F': must be a class or namespace when followed by '::' C:\local\boost_1_58_0\boost\bind\bind.hpp 69 1 HttpClientDemo
Error 2 error C2039: 'result_type' : is not a member of '`global namespace'' C:\local\boost_1_58_0\boost\bind\bind.hpp 69 1 HttpClientDemo
Error 3 error C2146: syntax error : missing ';' before identifier 'type' C:\local\boost_1_58_0\boost\bind\bind.hpp 69 1 HttpClientDemo
Error 4 error C2208: 'boost::_bi::type' : no members defined using this type C:\local\boost_1_58_0\boost\bind\bind.hpp 69 1 HttpClientDemo
Error 5 error C1903: unable to recover from previous error(s); stopping compilation C:\local\boost_1_58_0\boost\bind\bind.hpp 69 1 HttpClientDemo
此代码可能有什么问题?
答案 0 :(得分:3)
在client::handle_read_content
内,对boost::bind
的调用缺少参数。它应与client::handle_read_headers
中的相同:
boost::asio::async_read(socket_, response_,
boost::asio::transfer_at_least(1),
boost::bind(&client::handle_read_content, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred, // this line was missing
boost::ref(resp) // this line was missing
)
);