I've a class called Socket
, with two constructors:
Socket(int port){...}
Socket(string address, int port){...}
I'd like to use one instance of that Socket class as a private member of another class, the Connection class, like this:
class Connection{
private:
Socket socket;
//more stuff
};
In the constructor of the Connection
class I just want to pass as parameter one instance of Socket
and assign it to the private member, like this:
Connection:Connection(Socket socket){
this->socket = socket;
//...
}
But the compiler asks me to call the Socket
constructor inside the Connection constructor (or at least I think that); I'm getting this error:
error: no matching function for call to ‘Socket::Socket()’ Connection::Connection(Socket socket)
Which is the right way to do that (declaring the Socket
outside and passing it as parameter in the Connection
constructor)?