错误 C2825:"F":后跟 '::' 时必须是类或命名空间

error C2825: 'F': must be a class or namespace when followed by '::'

本文关键字:命名空间 后跟 错误 C2825      更新时间:2023-10-16

我在分析代码中错误的原因时遇到了一点麻烦。我的代码看起来很好,其他开发人员也说它很好:

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:localboost_1_58_0boostbindbind.hpp   69  1   HttpClientDemo
Error   2   error C2039: 'result_type' : is not a member of '`global namespace''    C:localboost_1_58_0boostbindbind.hpp   69  1   HttpClientDemo
Error   3   error C2146: syntax error : missing ';' before identifier 'type'    C:localboost_1_58_0boostbindbind.hpp   69  1   HttpClientDemo
Error   4   error C2208: 'boost::_bi::type' : no members defined using this type    C:localboost_1_58_0boostbindbind.hpp   69  1   HttpClientDemo
Error   5   error C1903: unable to recover from previous error(s); stopping compilation C:localboost_1_58_0boostbindbind.hpp   69  1   HttpClientDemo

这段代码可能有什么问题?

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 
        )
);