The function I'm trying to push into a thread:
void Send(sf::UdpSocket& newSocket, unsigned short& newPort, sf::IpAddress& newTargetIP, sf::Packet& newPackage)
{
string input;
cin >> input;
newPackage << input;
if(newSocket.send(newPackage, newTargetIP, newPort) != sf::Socket::Done)
cout << "Failed to send message." << endl;
else
cout << "You: " << input;
}
The thread construction:
sf::Thread Send(std::bind(&Send, socket, port, target, packet));
Error it gives:
'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'
This diagnostic occurred in the compiler generated function 'sf::Socket::Socket(const sf::Socket &)'
I know you can't copy sockets so I passed it though a reference, right? Sorry if it's an obvious answer.
Like this?
sf::Thread Send(std::cref(&Send, socket, port, target, packet));
It says it doesn't take its arguments.
Hi, I'm trying to do something similar and I have the same error.
I tried to do
sf::Thread send(std::bind(&send, ref(socket));
according to what I found in http://en.cppreference.com/w/cpp/utility/functional/bind (http://en.cppreference.com/w/cpp/utility/functional/bind)
but it didn't work saying that I'm still copying the socket (the same error).
I have no clue of what to do right now.
Indeed I made a mistake in the post, I'm sorry.
I actually did write void send(sf::TcpSocket client)
instead of void send(sf::TcpSocket &client)
in the prototype.
I did not make that mistake for the receive function though.
Thank you Nexus and asusralis, you helped me to finish my first project using SFML (the basic principle of a chat).