Ho una funzione che accetta un vettore di stringhe e ho una serie di quei vettori di stringhe in un vettore.Provare a passare il contenuto di un vettore a un thread
Volevo passare in rassegna il vettore che passa ogni vettore di stringhe a un nuovo thread.
for (vector<vector<string> >::iterator it = vecstringvec.begin() ;
it != vecstringvec.end(); ++it){
threadvector.push_back(thread(func, *it));
}
In sostanza, eccetto quanto sopra non funziona (errore di compilazione). Quello che credo è che ho bisogno di un std :: ref del vettore per passare, ma non sono sicuro esattamente, o come farlo usando l'iteratore.
errore completo:
/usr/include/c++/4.8/functional: In instantiation of ‘struct std::_Bind_simple<void (*(std::vector<std::basic_string<char> >, std::reference_wrapper<std::vector<std::basic_string<char> > >))(std::vector<std::basic_string<char> >&, std::vector<std::basic_string<char> >&)>’:
/usr/include/c++/4.8/thread:137:47: required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (&)(std::vector<std::basic_string<char> >&, std::vector<std::basic_string<char> >&); _Args = {std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, std::reference_wrapper<std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >}]’
prog.cpp:199:55: required from here
/usr/include/c++/4.8/functional:1697:61: error: no type named ‘type’ in ‘class std::result_of<void (*(std::vector<std::basic_string<char> >, std::reference_wrapper<std::vector<std::basic_string<char> > >))(std::vector<std::basic_string<char> >&, std::vector<std::basic_string<char> >&)>’
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<void (*(std::vector<std::basic_string<char> >, std::reference_wrapper<std::vector<std::basic_string<char> > >))(std::vector<std::basic_string<char> >&, std::vector<std::basic_string<char> >&)>’
_M_invoke(_Index_tuple<_Indices...>)
^
make: *** [prog.o] Error 1
Cosa ti fa pensare che non funzioni? – Johan
Quando ci si è seduti "non funziona", cosa intendi con questo? Puoi per favore elaborare? –
Un errore apparentemente troppo lungo per la casella di commento. Un sacco di cose come questa: ^ /usr/include/c++/4.8/functional:1727:9: errore: nessun tipo chiamato 'tipo' in 'classe std :: result_of)) (std :: basic_string , std :: vector >> &)>' _M_invoke (_Index_tuple <_Indices...>) –
user3816764