Thread problem in Objective

I dont know how to fix this:

1
2
3
void Misc::sendData(std::map<std::string, std::string> data) {
...
}


1
2
3
4
5
6
7
8
9
10
11
12
13
void Misc::loop(){
...
std::map<std::string, std::string> toSend = {};
...
toSend.insert({"m", tmp_str});
free(buffer);
// END

printf("Executing send thread...");

std::thread t1( &Misc::sendData , toSend );
t1.detach();
}


I got these errors:

1
2
3
4
D:\Qt\Tools\mingw530_32\i686-w64-mingw32\include\c++\functional:1426: error: static
 assertion failed: Wrong number of arguments for pointer-to-member
       static_assert(_Varargs::value
       ^


1
2
3
4
5
6
D:\Qt\Tools\mingw530_32\i686-w64-mingw32\include\c++\functional:1505: error: no type 
named 'type' in 'class std::result_of<std::_Mem_fn<void (Misc::*)
(std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >)>
(std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >)>'
       typedef typename result_of<_Callable(_Args...)>::type result_type;
                                                             ^


1
2
3
4
5
6
D:\Qt\Tools\mingw530_32\i686-w64-mingw32\include\c++\functional:1526: error: no type
 named 'type' in 'class std::result_of<std::_Mem_fn<void (Misc::*)
(std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >)>
(std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >)>'
         _M_invoke(_Index_tuple<_Indices...>)
         ^


Without thread it runs without errors.
Last edited on
&Misc::sendData try it without the &

I have not done modern threading yet, but every thread library I have used is just function *, not function **. the name of the function is already being converted to a * for you, the & doubles down..
Last edited on
Without "&" i got:
 
reference to non-static member function must be called
that error usually means you tried to call the member function without an object.
you cannot just call classname::function() in general, you must instead say classname var; var.function();

td::thread t1( &Misc::sendData ,

so that needs to be

td::thread t1( variable.sendData ,

or you need to make sendData static so it can be called without an object (this must be done very carefully, as object scope variables won't exist here if not also static).
Topic archived. No new replies allowed.