简体   繁体   English

Boost Library中的Io_context错误

[英]Io_context error in Boost Library

I'm trying to build a chat room using by Boost Libraries. 我正在尝试使用Boost Libraries建立一个聊天室。 But when I'm trying to use asio::io_context , the compiler says: 但是当我尝试使用asio::io_context ,编译器说:

io_context is not an member of asio. io_context不是asio的成员。

I built Boost 4 times and I thought maybe the problem was due to an installation failure on my part, but it doesn't seem to be. 我建了4次Boost,我想可能问题是由于我的安装失败,但似乎不是。

#include <ctime>
#include <iostream>
#include <string>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <boost/asio.hpp>

using boost::asio::ip::tcp;

std::string make_daytime_string()
{
    using namespace std; // For time_t, time and ctime;
    time_t now = time(0);
    return ctime(&now);
}

class tcp_connection
    : public boost::enable_shared_from_this<tcp_connection>
{
public:
    typedef boost::shared_ptr<tcp_connection> pointer;

    static pointer create(boost::asio::io_context& io_context)
    {
        return pointer(new tcp_connection(io_context));
    }

    tcp::socket& socket()
    {
        return socket_;
    }

    void start()
    {
        message_ = make_daytime_string();

        boost::asio::async_write(socket_, boost::asio::buffer(message_),
            boost::bind(&tcp_connection::handle_write, shared_from_this(),
                boost::asio::placeholders::error,
                boost::asio::placeholders::bytes_transferred));
    }

private:
    tcp_connection(boost::asio::io_context& io_context)
        : socket_(io_context)
    {
    }

    void handle_write(const boost::system::error_code& /*error*/,
        size_t /*bytes_transferred*/)
    {
    }

    tcp::socket socket_;
    std::string message_;
};

class tcp_server
{
public:
    tcp_server(boost::asio::io_context& io_context) //error
        : acceptor_(io_context, tcp::endpoint(tcp::v4(), 13)) //error
    {
        start_accept();
    }

Things changed in Boost 1.66: Boost 1.66改变了一些事情

在此输入图像描述

The release notes show the renamed/changed interfaces: 发行说明显示重命名/更改的界面:

Boost.Asio now provides the interfaces and functionality specified by the "C++ Extensions for Networking" Technical Specification. Boost.Asio现在提供“C ++网络扩展”技术规范指定的接口和功能。 In addition to access via the usual Boost.Asio header files, this functionality may be accessed through special headers that correspond to the header files defined in the TS. 除了通过通常的Boost.Asio头文件进行访问之外,还可以通过与TS中定义的头文件相对应的特殊头来访问此功能。 These are listed in the table below: 这些列在下表中:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 io_context的未定义符号:最新boost库的链接错误 - Undefined symbols for io_context: linking error for the latest boost library C ++错误:使用已删除的函数boost :: asio :: io_context :: io_context - c++ error: use of deleted function boost::asio::io_context::io_context 错误:“io_context”不是“boost::asio”的成员,错误:“steady_timer”不是“boost::asio”的成员 - error: ‘io_context’ is not a member of ‘boost::asio’ and error: ‘steady_timer’ is not a member of ‘boost::asio’ 对boost :: asio :: io_context :: run()和boost :: thread :: join()感到困惑 - Confused on boost::asio::io_context::run() and boost::thread::join() 提升 asio io_service 与 io_context - Boost asio io_service vs io_context 提高 websocket 和 io_context 的可重用性以重新建立连接 - boost websocket and io_context reusability for reestablishability of a connection 如何使用 Boost asio io_context post 绑定参数? - How to bind parameter with Boost asio io_context post? epoll 和 boost::asio::io_context 有什么区别? - What is the difference between epoll and boost::asio::io_context? boost::asio::io_context 套接字服务器 + thread_group - boost::asio::io_context Socket Server + thread_group 为什么 io_context 出现在我的 boost asio 协程服务器中 - Why io_context sopped in my boost asio coroutine server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM