我如何知道继承 boost::asio::basic_io_object 的 class 中的成员?

How do I know the members of this in a class that inherits boost::asio::basic_io_object?

我有这个class:

template < typename Service >
class BasicIOObject : public boost::asio::basic_io_object<Service>
{
public:
    explicit BasicIOObject(
        boost::asio::io_service &io_serviceIn, CString& fileNameIn)
    :   boost::asio::basic_io_object<Service>(io_serviceIn)
    {
        this->service.init(this->implementation, fileNameIn);
    }

    void wait()
    {
        this->service.wait(this->implementation);
    }

    template <typename Handler>
    void async_wait(Handler handler)
    {
        this->service.async_wait(this->implementation, handler);
    }

    void wait_handler(const boost::system::error_code &ec)
    {
        this->service.async_wait(
            this->implementation, boost::bind(&BasicIOObject::wait_handler, this, boost::asio::placeholders::error));
    }
};

而且我看不出 this 指的是什么?我还没有找到任何关于 boost::asio::basic_io_object 的文档,因此我们将不胜感激。

谢谢


好的,我知道 this 它指的是当前实例,但我怎么知道它有一个 service 成员?

boost::asio::basic_io_objectservice 个成员和 implementation 个成员。其中 service 的类型为 service_type,实际上是 basic_io_object 的模板参数,而 implementation_type 的类型为 service_type::implementation_type.

查找有关 Boost.Asio 类型和函数的文档的最佳位置之一是官方文档的 reference section . This page contains links to types, such as basic_io_object. For basic_io_object, it is documented that it has a service 受保护数据成员:

  • 弃用 ,并建议使用 get_service() 受保护的成员函数
  • 仅适用于不支持移动性的服务
  • 具有 service_type, which is the template template parameter provided to basic_io_object<> that must be a model of the IoObjectService 类型要求