Error C2039: 'result_type': is not a member of the 'global namespace'
My application is throwing this error:
error C2039: 'result_type' : is not a member of '`global namespace''
for this code:
void handle_read_headers(const boost::system::error_code& err, RESTClient::response& resp)
{
if (!err)
{
// Process the response headers.
std::istream response_stream(&response_);
std::string header;
while (std::getline(response_stream, header) && header != "\r")
std::cout << header << "\n";
std::cout << "\n";
// Write whatever content we already have to output.
if (response_.size() > 0)
std::cout << &response_;
(&resp)->body = "Yehey!!!";
// 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::ref(resp)));
}
else
{
std::cout << "Error: " << err << "\n";
}
}
The bound function looks like this:
void handle_read_content(const boost::system::error_code& err, RESTClient::response& resp){}
What could be wrong with my code?
Update:
I was able to compile the code with these changes
source to share
According to this page of the ReadHandler documentation, you need to take both the error code and the number of bytes transferred.
Perhaps MSVC is more picky / sensitive about missing placeholders when invoking a binding expression .ยน
Try adding the placeholder parameter to bind:
// 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)));
And obviously for the handler function itself:
void handle_read_content(const boost::system::error_code& ec, size_t bytes_transferred, RESTClient::response& resp){}
Update
I spent an unreasonable amount of effort (thanks @qballer, @nab and others live too!) To reproduce this in Visual Studio and got this:
For the record:
- Win32
- Boost 1_58_0
- OpenSSL-1.0.2c-i386-win32
- Visual Studio 2013 Update 4
ยน in fact, I've sometimes noticed that Asio accepts slightly different signatures for handler functions using GCC (my preferred compiler). I've always wondered if this is a feature or perhaps a bug?
source to share