July 2015
Intermediate to advanced
558 pages
13h 31m
English
Copy semantics are for creating clones of objects. It is useful sometimes, but not always needed or even meaningful. Consider the following class that encapsulates a TCP client socket. A TCP socket is an integer that represents one endpoint of a TCP connection and through which data can be sent or received to the other endpoint. The TCP socket class can have the following interface:
class TCPSocket
{
public:
TCPSocket(const std::string& host, const std::string& port);
~TCPSocket();
bool is_open();
vector<char> read(size_t to_read);
size_t write(vector<char> payload);
private:
int socket_fd_;
TCPSocket(const TCPSocket&);
TCPSocket& operator = (const TCPSocket&);
};The constructor opens a connection to a host ...
Read now
Unlock full access