// 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类的成员变量 }
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/280446.html