poco c++ ,成员类为何声明为引用类型? 1C

namespace
{
class EchoServiceHandler
{
public:
EchoServiceHandler(StreamSocket& socket, SocketReactor& reactor):
_socket(socket),
_reactor(reactor)
{
_reactor.addEventHandler(_socket, Observer(*this, &EchoServiceHandler::onReadable));
}

    ~EchoServiceHandler()
    {
        _reactor.removeEventHandler(_socket, Observer<EchoServiceHandler, ReadableNotification>(*this, &EchoServiceHandler::onReadable));
    }

    void onReadable(ReadableNotification* pNf)
    {
        pNf->release();
        char buffer[8];
        int n = _socket.receiveBytes(buffer, sizeof(buffer));
        if (n > 0)
        {
            _socket.sendBytes(buffer, n);
        }
        else
        {
            _socket.shutdownSend();
            delete this;
        }
    }

private:
    StreamSocket   _socket;
    SocketReactor& _reactor;  //here
};

我去掉引用,gcc编译不过去。。
把成员类声明为引用,有什么作用。
c++
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐