I have attempted to move over to using std::bind; however I get the following error message:
1>------ Build started: Project: GameServer, Configuration: Release Win32 ------
1> Heatbeat.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(28): error C2825: '_Fty': must be a class or namespace when followed by '::'
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(40) : see reference to class template instantiation 'std::tr1::_Result_type1<__formal,_Fty,_Arg0>' being compiled
1> with
1> [
1> __formal=false,
1> _Fty=void (__thiscall Heartbeat::* const )(sf::IpAddress),
1> _Arg0=std::tr1::_Nil &
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(597) : see reference to class template instantiation 'std::tr1::_Result_of1<_Fty,_Farg0>' being compiled
1> with
1> [
1> _Fty=void (__thiscall Heartbeat::* const )(sf::IpAddress),
1> _Farg0=std::tr1::_Nil &
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xrefwrap(28) : see reference to class template instantiation 'std::tr1::_Result_of<_Ty>' being compiled
1> with
1> [
1> _Ty=void (__thiscall Heartbeat::* const (std::tr1::_Nil &))(sf::IpAddress)
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxbind1(273) : see reference to class template instantiation 'std::tr1::result_of<_Fty>' being compiled
1> with
1> [
1> _Fty=void (__thiscall Heartbeat::* const (std::tr1::_Nil &))(sf::IpAddress)
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxbind0(10) : see reference to class template instantiation 'std::tr1::_Bind1<_Callable,_Arg0>::_Return<_Barg0,_Barg1,_Barg2,_Barg3,_Barg4,_Barg5,_Barg6,_Barg7,_Barg8,_Barg9>' being compiled
1> with
1> [
1> _Callable=std::tr1::_Callable_pmd<void (__thiscall Heartbeat::* const )(sf::IpAddress),Heartbeat>,
1> _Arg0=sf::IpAddress,
1> _Barg0=std::tr1::_Nil &,
1> _Barg1=std::tr1::_Nil &,
1> _Barg2=std::tr1::_Nil &,
1> _Barg3=std::tr1::_Nil &,
1> _Barg4=std::tr1::_Nil &,
1> _Barg5=std::tr1::_Nil &,
1> _Barg6=std::tr1::_Nil &,
1> _Barg7=std::tr1::_Nil &,
1> _Barg8=std::tr1::_Nil &,
1> _Barg9=std::tr1::_Nil &
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\functional(394) : see reference to class template instantiation 'std::tr1::_Bind_base<_Ret,_BindN>' being compiled
1> with
1> [
1> _Ret=void (sf::IpAddress),
1> _BindN=std::tr1::_Bind1<std::tr1::_Callable_pmd<void (__thiscall Heartbeat::* const )(sf::IpAddress),Heartbeat>,sf::IpAddress>
1> ]
1> Heatbeat.cpp(23) : see reference to class template instantiation 'std::tr1::_Bind<_Result_type,_Ret,_BindN>' being compiled
1> with
1> [
1> _Result_type=std::tr1::_Notforced,
1> _Ret=void (sf::IpAddress),
1> _BindN=std::tr1::_Bind1<std::tr1::_Callable_pmd<void (__thiscall Heartbeat::* const )(sf::IpAddress),Heartbeat>,sf::IpAddress>
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(28): error C2903: 'result' : symbol is neither a class template nor a function template
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(28): error C2039: 'result' : is not a member of '`global namespace''
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(28): error C2143: syntax error : missing ';' before '<'
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(28): error C2039: 'type' : is not a member of '`global namespace''
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(28): error C2238: unexpected token(s) preceding ';'
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(40): error C2039: '_Type' : is not a member of 'std::tr1::_Result_type1<__formal,_Fty,_Arg0>'
1> with
1> [
1> __formal=false,
1> _Fty=void (__thiscall Heartbeat::* const )(sf::IpAddress),
1> _Arg0=std::tr1::_Nil &
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(40): error C2146: syntax error : missing ';' before identifier '_Type'
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(40): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(40): error C2602: 'std::tr1::_Result_of1<_Fty,_Farg0>::_Type' is not a member of a base class of 'std::tr1::_Result_of1<_Fty,_Farg0>'
1> with
1> [
1> _Fty=void (__thiscall Heartbeat::* const )(sf::IpAddress),
1> _Farg0=std::tr1::_Nil &
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(40) : see declaration of 'std::tr1::_Result_of1<_Fty,_Farg0>::_Type'
1> with
1> [
1> _Fty=void (__thiscall Heartbeat::* const )(sf::IpAddress),
1> _Farg0=std::tr1::_Nil &
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult(40): error C2868: 'std::tr1::_Result_of1<_Fty,_Farg0>::_Type' : illegal syntax for using-declaration; expected qualified-name
1> with
1> [
1> _Fty=void (__thiscall Heartbeat::* const )(sf::IpAddress),
1> _Farg0=std::tr1::_Nil &
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxbind0(12): error C2091: function returns function
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxbind0(27): error C2091: function returns function
1> ServerCore.cpp
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Here is the modified code (so now the thread isn't instantly terminated. Overlooked that!):
Heartbeat::Heartbeat(ClientHandler clients)
{
std::vector<sf::IpAddress> ips;
for(int i = 0; i < clients.size(); i++)
{
PlayerSession player = clients.getPlayers().at(i);
sf::IpAddress ip = player.getIp();
ips.push_back(player.getIp());
std::cout << player.getIp() << std::endl;
sf::Thread thread(std::bind(&Heartbeat::heartbeat, ip));
thread.launch();
}
}
Everything else has stayed the same.
EDIT: Forgot to actually include the "this" in the bind call. The thread should run fine now. Thanks!