I'm 'modernizing' some piece of code to c++11 'standards' (std::thread etc), I'm trying to spawn a thread using std::thread and passing a class as a parameter but I can't get it to work for some reason..
Class definition:
Class Listener
{
...
private:
...
Class Worker
{
...
public:
Worker(struct sockaddr_in server_sockaddr, struct sockaddr_in client_sockaddr, socklen_t blah, int blah2)
{
....
}
};
...
int mah_function_in_class_Listener()
{
...
thread thread_id=thread(Worker(server_sockaddr, client_sockaddr, client_addr_size, accpt));
...
}
};
When I try to compile this I get:
In file included from /usr/include/c++/4.8/thread:39:0,
from ./tcp_server_singlethreaded.cpp:26:
/usr/include/c++/4.8/functional: In instantiation of ‘struct std::_Bind_simple<Listener::Worker()>’:
/usr/include/c++/4.8/thread:137:47: required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = Listener::Worker; _Args = {}]’
./tcp_server_singlethreaded.cpp:199:106: required from here
/usr/include/c++/4.8/functional:1697:61: error: no type named ‘type’ in ‘class std::result_of<Listener::Worker()>’
typedef typename result_of<_Callable(_Args...)>::type result_type;
^
/usr/include/c++/4.8/functional:1727:9: error: no type named ‘type’ in ‘class std::result_of<Listener::Worker()>’
_M_invoke(_Index_tuple<_Indices...>)
^
As far as I understand this is happening because an std::thread object is being returned, rather than object thread_id of type std::thread (?? :S), I thought a copy initialization or using {} would resolve this, but apparently there's something else wrong here..
Thanks for taking a look - hopefully someone will be able to help with this
Many thanks!
EDIT
I forgot to mention a minor detail.. g++ / gcc 4.8.2 (4.8.2-19 ubuntu) -- I don't think this is a gcc prob (more likely a pebkac issue)..