简体   繁体   English

错误:没有匹配的 function 调用 'std::thread::_Invoker <std::tuple< div><div id="text_translate"><p> 我正面临线程问题。</p><p> 我试图在 Chronometer class 的线程内执行 function,包括一个 while 循环:</p><p> 这是部分代码:</p><pre> for(int i = 0; i<car_data.size();i++) { if(car_data[i]->checkArea(frame, pt1_zone, pt2_zone)) { std::thread(&Chronometer::start_chrono, car_crono[i], std::ref(chrono)); cv::rectangle(frame, car_data[i]->pt1, car_data[i]->pt2, cv::Scalar(255,0,0), 1, cv::LINE_8,0); //cv::putText(frame, "Parked", car_data[i]->pt1, cv::FONT_HERSHEY_DUPLEX, 0.9, cv::Scalar( 50, 255, 50 )); //occupancy_state = place.occupancyTrue(); //place_1.occupancy = true;</pre><p> car_crono 和 chrono 的类型</p><pre>std::vector<Chronometer*> car_crono; Chronometer chrono;</pre><p> 这是我的 class 计时器:</p><pre> class Chronometer { private: static int hour, min, sec; //std::stringstream ss; //Chronometer chrono; public: Chronometer(); static Chronometer& start_chrono(Chronometer& chrono); static Chronometer& finish_chrono(Chronometer& chrono); friend std::ostream& operator<<(std::ostream& flux, Chronometer t); Chronometer& operator=(const Chronometer& other); ~Chronometer(); };</pre><p> 对于线程,我尝试了几种参数。 最后一个:</p><pre> std::thread(&Chronometer::start_chrono, car_crono[i], std::ref(chrono));</pre><p> 我猜 ref 是必要的,但没有改变。</p><p> 这是完整的错误</p><pre>/usr/include/c++/7/thread: In instantiation of 'struct std::thread::_Invoker<std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> > >': /usr/include/c++/7/thread:127:22: required from 'std::thread::thread(_Callable&&, _Args&&...) [with _Callable = Chronometer& (*)(Chronometer&); _Args = {Chronometer*&, std::reference_wrapper<Chronometer>}]' recognizer_rtsp.cxx:348:76: required from here /usr/include/c++/7/thread:240:2: error: no matching function for call to 'std::thread::_Invoker<std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> > >::_M_invoke(std::thread::_Invoker<std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> > >::_Indices)' operator()() ^~~~~~~~ /usr/include/c++/7/thread:231:4: note: candidate: template<long unsigned int..._Ind> decltype (std::__invoke((_S_declval<_Ind>)()...)) std::thread::_Invoker<_Tuple>::_M_invoke(std::_Index_tuple<_Ind...>) [with long unsigned int..._Ind = {_Ind...}; _Tuple = std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> >] _M_invoke(_Index_tuple<_Ind...>) ^~~~~~~~~ /usr/include/c++/7/thread:231:4: note: template argument deduction/substitution failed: /usr/include/c++/7/thread: In substitution of 'template<long unsigned int..._Ind> decltype (std::__invoke(_S_declval<_Ind>()...)) std::thread::_Invoker<std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> > >::_M_invoke<_Ind...>(std::_Index_tuple<_Ind1...>) [with long unsigned int..._Ind = {0, 1, 2}]': /usr/include/c++/7/thread:240:2: required from 'struct std::thread::_Invoker<std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> > >' /usr/include/c++/7/thread:127:22: required from 'std::thread::thread(_Callable&&, _Args&&...) [with _Callable = Chronometer& (*)(Chronometer&); _Args = {Chronometer*&, std::reference_wrapper<Chronometer>}]' recognizer_rtsp.cxx:348:76: required from here /usr/include/c++/7/thread:233:29: error: no matching function for call to '__invoke(std::__tuple_element_t<0, std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> > >, std::__tuple_element_t<1, std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> > >, std::__tuple_element_t<2, std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> > >)' -> decltype(std::__invoke(_S_declval<_Ind>()...)) ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/7/tuple:41:0, from /usr/include/c++/7/bits/stl_map.h:63, from /usr/include/c++/7/map:61, from../alpr_utils.h:7, from recognizer_rtsp.cxx:34: /usr/include/c++/7/bits/invoke.h:89:5: note: candidate: template<class _Callable, class... _Args> constexpr typename std::__invoke_result<_Functor, _ArgTypes>::type std::__invoke(_Callable&&, _Args&&...) __invoke(_Callable&& __fn, _Args&&... __args) ^~~~~~~~ /usr/include/c++/7/bits/invoke.h:89:5: note: template argument deduction/substitution failed: /usr/include/c++/7/bits/invoke.h: In substitution of 'template<class _Callable, class... _Args> constexpr typename std::__invoke_result<_Functor, _ArgTypes>::type std::__invoke(_Callable&&, _Args&&...) [with _Callable = Chronometer& (*)(Chronometer&); _Args = {Chronometer*, std::reference_wrapper<Chronometer>}]': /usr/include/c++/7/thread:233:29: required by substitution of 'template<long unsigned int..._Ind> decltype (std::__invoke(_S_declval<_Ind>()...)) std::thread::_Invoker<std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> > >::_M_invoke<_Ind...>(std::_Index_tuple<_Ind1...>) [with long unsigned int..._Ind = {0, 1, 2}]' /usr/include/c++/7/thread:240:2: required from 'struct std::thread::_Invoker<std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> > >' /usr/include/c++/7/thread:127:22: required from 'std::thread::thread(_Callable&&, _Args&&...) [with _Callable = Chronometer& (*)(Chronometer&); _Args = {Chronometer*&, std::reference_wrapper<Chronometer>}]' recognizer_rtsp.cxx:348:76: required from here /usr/include/c++/7/bits/invoke.h:89:5: error: no type named 'type' in 'struct std::__invoke_result<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> >'</pre><p> 我应该通过线程传递什么样的参数?</p><p> 我去了几个链接来寻找解决方案,但没有什么能解决我的问题:</p><p> <a href="https://stackoverflow.com/questions/21048906/stdthread-pass-by-reference-calls-copy-constructor" rel="nofollow noreferrer">std::thread 通过引用传递调用复制构造函数</a></p><p> <a href="https://stackoverflow.com/questions/67625058/no-matching-function-to-invoke-using-stdthread" rel="nofollow noreferrer">没有匹配的 function 调用,使用 std::thread</a></p><p> ... </p></div></std::tuple<>

[英]error: no matching function for call to ‘std::thread::_Invoker<std::tuple

I'm facing a thread problem.我正面临线程问题。

I tried to execute function inside a thread from Chronometer class including a while loop:我试图在 Chronometer class 的线程内执行 function,包括一个 while 循环:

Here is the part code:这是部分代码:

for(int i = 0; i<car_data.size();i++)
            {
                if(car_data[i]->checkArea(frame, pt1_zone, pt2_zone))
                {
                    std::thread(&Chronometer::start_chrono, car_crono[i], std::ref(chrono));                            
                    cv::rectangle(frame, car_data[i]->pt1, car_data[i]->pt2, cv::Scalar(255,0,0), 1, cv::LINE_8,0);
                    //cv::putText(frame, "Parked", car_data[i]->pt1, cv::FONT_HERSHEY_DUPLEX, 0.9, cv::Scalar( 50, 255, 50 ));
                    //occupancy_state = place.occupancyTrue();
                    //place_1.occupancy = true;

The type of car_crono and chrono car_crono 和 chrono 的类型

std::vector<Chronometer*> car_crono;
Chronometer chrono;

Here is my class Chronometer:这是我的 class 计时器:

class Chronometer
{
    private:
        static int hour, min, sec;
        //std::stringstream ss;
        //Chronometer chrono;

    public:

        Chronometer();
        static Chronometer& start_chrono(Chronometer& chrono);
        static Chronometer& finish_chrono(Chronometer& chrono);
        friend std::ostream& operator<<(std::ostream& flux, Chronometer t);
        Chronometer& operator=(const Chronometer& other);
        ~Chronometer();

};

For the thread I tried several kind of parameters.对于线程,我尝试了几种参数。 The last one:最后一个:

std::thread(&Chronometer::start_chrono, car_crono[i], std::ref(chrono));        

I guessed a ref was necessary but doesn't change.我猜 ref 是必要的,但没有改变。

Here is the full error这是完整的错误

/usr/include/c++/7/thread: In instantiation of ‘struct std::thread::_Invoker<std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> > >’:
/usr/include/c++/7/thread:127:22:   required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = Chronometer& (*)(Chronometer&); _Args = {Chronometer*&, std::reference_wrapper<Chronometer>}]’
recognizer_rtsp.cxx:348:76:   required from here
/usr/include/c++/7/thread:240:2: error: no matching function for call to ‘std::thread::_Invoker<std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> > >::_M_invoke(std::thread::_Invoker<std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> > >::_Indices)’
  operator()()
  ^~~~~~~~
/usr/include/c++/7/thread:231:4: note: candidate: template<long unsigned int ..._Ind> decltype (std::__invoke((_S_declval<_Ind>)()...)) std::thread::_Invoker<_Tuple>::_M_invoke(std::_Index_tuple<_Ind ...>) [with long unsigned int ..._Ind = {_Ind ...}; _Tuple = std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> >]
    _M_invoke(_Index_tuple<_Ind...>)
    ^~~~~~~~~
/usr/include/c++/7/thread:231:4: note:   template argument deduction/substitution failed:
/usr/include/c++/7/thread: In substitution of ‘template<long unsigned int ..._Ind> decltype (std::__invoke(_S_declval<_Ind>()...)) std::thread::_Invoker<std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> > >::_M_invoke<_Ind ...>(std::_Index_tuple<_Ind1 ...>) [with long unsigned int ..._Ind = {0, 1, 2}]’:
/usr/include/c++/7/thread:240:2:   required from ‘struct std::thread::_Invoker<std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> > >’
/usr/include/c++/7/thread:127:22:   required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = Chronometer& (*)(Chronometer&); _Args = {Chronometer*&, std::reference_wrapper<Chronometer>}]’
recognizer_rtsp.cxx:348:76:   required from here
/usr/include/c++/7/thread:233:29: error: no matching function for call to ‘__invoke(std::__tuple_element_t<0, std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> > >, std::__tuple_element_t<1, std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> > >, std::__tuple_element_t<2, std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> > >)’
    -> decltype(std::__invoke(_S_declval<_Ind>()...))
                ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/tuple:41:0,
                 from /usr/include/c++/7/bits/stl_map.h:63,
                 from /usr/include/c++/7/map:61,
                 from ../alpr_utils.h:7,
                 from recognizer_rtsp.cxx:34:
/usr/include/c++/7/bits/invoke.h:89:5: note: candidate: template<class _Callable, class ... _Args> constexpr typename std::__invoke_result<_Functor, _ArgTypes>::type std::__invoke(_Callable&&, _Args&& ...)
     __invoke(_Callable&& __fn, _Args&&... __args)
     ^~~~~~~~
/usr/include/c++/7/bits/invoke.h:89:5: note:   template argument deduction/substitution failed:
/usr/include/c++/7/bits/invoke.h: In substitution of ‘template<class _Callable, class ... _Args> constexpr typename std::__invoke_result<_Functor, _ArgTypes>::type std::__invoke(_Callable&&, _Args&& ...) [with _Callable = Chronometer& (*)(Chronometer&); _Args = {Chronometer*, std::reference_wrapper<Chronometer>}]’:
/usr/include/c++/7/thread:233:29:   required by substitution of ‘template<long unsigned int ..._Ind> decltype (std::__invoke(_S_declval<_Ind>()...)) std::thread::_Invoker<std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> > >::_M_invoke<_Ind ...>(std::_Index_tuple<_Ind1 ...>) [with long unsigned int ..._Ind = {0, 1, 2}]’
/usr/include/c++/7/thread:240:2:   required from ‘struct std::thread::_Invoker<std::tuple<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> > >’
/usr/include/c++/7/thread:127:22:   required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = Chronometer& (*)(Chronometer&); _Args = {Chronometer*&, std::reference_wrapper<Chronometer>}]’
recognizer_rtsp.cxx:348:76:   required from here
/usr/include/c++/7/bits/invoke.h:89:5: error: no type named ‘type’ in ‘struct std::__invoke_result<Chronometer& (*)(Chronometer&), Chronometer*, std::reference_wrapper<Chronometer> >’

What kind of parameter should I pass through the thread?我应该通过线程传递什么样的参数?

I went to several links to find a solution but nothing could solve my problem:我去了几个链接来寻找解决方案,但没有什么能解决我的问题:

std::thread pass by reference calls copy constructor std::thread 通过引用传递调用复制构造函数

No matching function to invoke, using std::thread 没有匹配的 function 调用,使用 std::thread

... ...

Chronometer::start_chrono is a static function, so it's not bound to any object, ie doesn't need an object to called upon. Chronometer::start_chrono是一个 static function,因此它不绑定到任何 object,即不需要调用 object。

Static member functions are not associated with any object. When called, they have no this pointer. Static成员函数不关联任何object,调用时没有this指针。

You should have simply written.你应该简单地写。

std::thread(&Chronometer::start_chrono, std::ref(chrono));  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:没有用于调用 std::thread 的匹配函数 - error: no matching function for call to std::thread C ++ 11 std :: thread给出错误:没有匹配函数来调用std :: thread :: thread - C++11 std::thread giving error: no matching function to call std::thread::thread 使用线程编程时std :: thread :: _ Invoker错误 - std::thread::_Invoker error while programming withthreads 没有用于调用std :: vector的匹配函数 <std::tuple> 推回 - no matching function for call to std::vector<std::tuple> push_back std :: function and error:没有匹配函数用于调用 - std::function and error: no matching function for call to 错误:没有匹配的 function 调用 'Node::Node()' - second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...) - error: no matching function for call to 'Node::Node()' - second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...) C++ 多线程错误:没有匹配的 function 调用 'std::thread::thread(<unresolved overloaded function type></unresolved> - C++ Multithreading Error : no matching function for call to 'std::thread::thread(<unresolved overloaded function type> 错误:没有匹配函数来调用...(std :: string&) - error: no matching function for call to…(std::string&) 使用std :: find没有匹配的函数调用错误 - no matching function call error using std::find 没有匹配的函数来调用&#39;std :: advance&#39;错误 - No matching function for call to 'std::advance' error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM