Hello, I try not to ask questions, however; all day I have been reading through the forums, stack overflow, and various other places searching for an answer, unfortunately to no avail. What I am trying to accomplish is storing TcpSockets, I have come to the conclusion that I will need to use Smart Pointers or move semantics (which SFML does not yet support, SFML3.0?
). I have never used Smart pointers so I read up on them a bit, and thought that I understood, but I was apparently wrong because I can't seem to get my wrapper class to work. Below is the code I have, I know of some various errors that I will point out, but don't know how to fix. If there is anything that I miss it would be appreciated if you could help with that too.
Code:
class Client
{
public:
Client() //I think I need to take the TcpSocket here and make the std::unique_ptr point to it. But I can't, it says I am copying the socket.
{
}
~Client()
{
_sockPtr->disconnect();
}
sf::TcpSocket& getSocket()
{
return *_sockPtr;
}
private:
std::unique_ptr<sf::TcpSocket> _sockPtr;
};
And this is the code I am using to accept clients. It's a bit rough right now.
if (Selector.isReady(Listener))
{
Client client;
Connections.push_back(client);
if (Listener.accept(Connections[Connections.size() - 1].getSocket()) != sf::Socket::Done)
{
//error
}
else
{
std::cout << "Client Connected." << std::endl;
}
}
I'm sorry if the answer is just really simply. I am just having trouble figuring it out.