Я пытаюсь реализовать поток на C++, который будет использоваться для управления моментом съемки, но этот простой код выдает странную ошибку, которую я не могу понять. Это мой код:
1>------ Build started: Project: Proyecto para pruebas OPENCV, Configuration:
Release x64 ------
1> Main.cpp
1>Main.cpp(46): warning C4244: 'initializing': conversion from '__int64' to 'int', possible loss of data
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(238): error C2893: Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...)'
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(238): note: With the following template arguments:
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(238): note: '_Callable=void (__cdecl *)(int,bool &,bool &)'
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(238): note: '_Types={int, bool, bool}'
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(247): note: see reference to function template instantiation 'void std::_LaunchPad::_Execute(std::tuple &,std::integer_sequence)' being compiled
1> with
1> [
1> _Target=std::unique_ptr,
1> _Ty=size_t
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(247): note: see reference to function template instantiation 'void std::_LaunchPad::_Execute(std::tuple &,std::integer_sequence)' being compiled
1> with
1> [
1> _Target=std::unique_ptr,
1> _Ty=size_t
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(242): note: while compiling class template member function 'void std::_LaunchPad::_Run(std::_LaunchPad *) noexcept'
1> with
1> [
1> _Target=std::unique_ptr
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(230): note: see reference to function template instantiation 'void std::_LaunchPad::_Run(std::_LaunchPad *) noexcept' being compiled
1> with
1> [
1> _Target=std::unique_ptr
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(256): note: see reference to class template instantiation 'std::_LaunchPad' being compiled
1> with
1> [
1> _Target=std::unique_ptr
1> ]
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thread(52): note: see reference to function template instantiation 'void std::_Launch(_Thrd_t *,_Target &&)' being compiled
1> with
1> [
1> _Target=std::unique_ptr
1> ]
1> Main.cpp(136): note: see reference to function template instantiation 'std::thread::thread(_Fn,int &,bool &,bool &)' being compiled
1> with
1> [
1> _Fn=void (__cdecl &)(int,bool &,bool &)
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Что еще более странно, так это то, что у меня есть аналогичный код в другой программе, и он компилируется без ошибок!
Кто-нибудь знает, что не так с этим кодом?
Спасибо!
Я пытаюсь реализовать поток на C++, который будет использоваться для управления моментом съемки, но этот простой код выдает странную ошибку, которую я не могу понять. Это мой код: [code]#include #include #include using namespace std;
thread t(counter, seconds, takePhoto, threadStart); //Some code here }
void counter(int seconds, bool &flagTakePhoto, bool &flagThreadStart) { while (flagThreadStart) { this_thread::sleep_for(chrono::seconds(seconds)); flagTakePhoto = true; } terminate(); } [/code] Это ошибка: [code]1>------ Build started: Project: Proyecto para pruebas OPENCV, Configuration: Release x64 ------ 1> Main.cpp 1>Main.cpp(46): warning C4244: 'initializing': conversion from '__int64' to 'int', possible loss of data 1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(238): error C2893: Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...)' 1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(238): note: With the following template arguments: 1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(238): note: '_Callable=void (__cdecl *)(int,bool &,bool &)' 1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(238): note: '_Types={int, bool, bool}' 1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(247): note: see reference to function template instantiation 'void std::_LaunchPad::_Execute(std::tuple &,std::integer_sequence)' being compiled 1> with 1> [ 1> _Target=std::unique_ptr, 1> _Ty=size_t 1> ] 1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(247): note: see reference to function template instantiation 'void std::_LaunchPad::_Execute(std::tuple &,std::integer_sequence)' being compiled 1> with 1> [ 1> _Target=std::unique_ptr, 1> _Ty=size_t 1> ] 1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(242): note: while compiling class template member function 'void std::_LaunchPad::_Run(std::_LaunchPad *) noexcept' 1> with 1> [ 1> _Target=std::unique_ptr 1> ] 1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(230): note: see reference to function template instantiation 'void std::_LaunchPad::_Run(std::_LaunchPad *) noexcept' being compiled 1> with 1> [ 1> _Target=std::unique_ptr 1> ] 1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thr/xthread(256): note: see reference to class template instantiation 'std::_LaunchPad' being compiled 1> with 1> [ 1> _Target=std::unique_ptr 1> ] 1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\thread(52): note: see reference to function template instantiation 'void std::_Launch(_Thrd_t *,_Target &&)' being compiled 1> with 1> [ 1> _Target=std::unique_ptr 1> ] 1> Main.cpp(136): note: see reference to function template instantiation 'std::thread::thread(_Fn,int &,bool &,bool &)' being compiled 1> with 1> [ 1> _Fn=void (__cdecl &)(int,bool &,bool &) 1> ] ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== [/code] Что еще более странно, так это то, что у меня есть аналогичный код в другой программе, и он компилируется без ошибок! Кто-нибудь знает, что не так с этим кодом? Спасибо!