静态类也受保护吗?因为没有对象可以被实例化,它必须被继承。我只想确保无法访问 Socket 成员,除非它直接与 ServerSocket 通信
i.e.
//Socket.cpp
static class Socket {
Socket();
Socket(PORT);
~Socket();
int create();
int bind();
int listen();
int connect();
int close();
int send(char* data);
int recv(char* data);
};
//ServerSocket.cpp
class ServerSocket : private Socket {
ServerSocket();
ServerSocket(PORT);
~ServerSocket();
close();
send(char* data);
recv(char* data);
};
// main.cpp
int main() {
ServerSocket socket(30000);
socket.send("Hello World");
socket.close();
return 0;
};