Код: Выделить всё
#include
#include
#include
using namespace std;
void counter(int seconds, bool &flagTakePhoto, bool &flagThreadStart);
int main() {
bool takePhoto, threadStart;
int seconds = 1;
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();
}
Код: Выделить всё
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 ==========
Кто-нибудь знает, что не так с этим кодом?
Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/327 ... in-threads