编程语言
首页 > 编程语言> > 实现0开销的 c++ 接口例子

实现0开销的 c++ 接口例子

作者:互联网

// network.h
class Network
{
public:
    bool send(const char* host, 
              uint16_t port, 
              const std::string& message);
    static Network* New();
    static void Delete(Network* network);

protected:
    Network();
    ~Network();
}

// network.cpp
bool Network::send(const char* host, 
                   uint16_t port, 
                   const std::string& message)
{
    NetworkImpl* impl = (NetworkImpl*)this;
    //通过impl访问成员变量,实现Network
}
static Network* New()
{
    return new NetworkImpl();
}

static void Delete(Network* network)
{
    delete (NetworkImpl*)network;
}


// networkimpl.h
class NetworkImpl : public Network
{
    friend class Network;

private:
    //Network类的成员变量
}

  

标签:开销,const,network,接口,static,c++,NetworkImpl,class,Network
来源: https://www.cnblogs.com/kingkaixuan/p/16584986.html