简体   繁体   中英

error C2039: 'result_type' : is not a member of '`global namespace''

My app 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 in my code?

Update:

I was able to compile the code with these changes

在此处输入图片说明

According to this documentation page ReadHandler needs to take and error code as well as the number of bytes transferred.

It might be that MSVC is more picky/sensitive about the missing placeholders when invoking a bind expression.¹

Try adding the placeholder parameter to the 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 to the handler function itself too:

void handle_read_content(const boost::system::error_code& ec, size_t bytes_transferred, RESTClient::response& resp){}

Update

I have spent unreasonable amounts of effort (thanks to @qballer, @nab, and others on the live feed too!) to reproduce this in Visual Studio and got this:

在此处输入图片说明

For the record: that was

  • 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 whether that is a feature, or perhaps a bug?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM