#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <thread>
#include <mutex>
using namespace std;
struct Foo {
private:
int _i = 0;
std::mutex _mutex;
public:
int f() const
{
std::lock_guard<std::mutex> locker(_mutex);
return _i;
}
};
int main()
{
Foo foo;
foo.f();
cin.get();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnN0cmVhbT4KI2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8dGhyZWFkPgojaW5jbHVkZSA8bXV0ZXg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJ1Y3QgRm9vIHsKcHJpdmF0ZToKCWludCBfaSA9IDA7CglzdGQ6Om11dGV4IF9tdXRleDsKcHVibGljOgoJaW50IGYoKSBjb25zdAoJewoJCXN0ZDo6bG9ja19ndWFyZDxzdGQ6Om11dGV4PiBsb2NrZXIoX211dGV4KTsKCQlyZXR1cm4gX2k7Cgl9Cgp9OwoKaW50IG1haW4oKQp7CglGb28gZm9vOwoJZm9vLmYoKTsKCWNpbi5nZXQoKTsKCXJldHVybiAwOwp9
prog.cpp: In member function 'int Foo::f() const':
prog.cpp:16:44: error: no matching function for call to 'std::lock_guard<std::mutex>::lock_guard(const std::mutex&)'
std::lock_guard<std::mutex> locker(_mutex);
^
prog.cpp:16:44: note: candidates are:
In file included from prog.cpp:6:0:
/usr/include/c++/4.9/mutex:379:7: note: std::lock_guard<_Mutex>::lock_guard(std::lock_guard<_Mutex>::mutex_type&, std::adopt_lock_t) [with _Mutex = std::mutex; std::lock_guard<_Mutex>::mutex_type = std::mutex]
lock_guard(mutex_type& __m, adopt_lock_t) : _M_device(__m)
^
/usr/include/c++/4.9/mutex:379:7: note: candidate expects 2 arguments, 1 provided
/usr/include/c++/4.9/mutex:376:16: note: std::lock_guard<_Mutex>::lock_guard(std::lock_guard<_Mutex>::mutex_type&) [with _Mutex = std::mutex; std::lock_guard<_Mutex>::mutex_type = std::mutex]
explicit lock_guard(mutex_type& __m) : _M_device(__m)
^
/usr/include/c++/4.9/mutex:376:16: note: no known conversion for argument 1 from 'const std::mutex' to 'std::lock_guard<std::mutex>::mutex_type& {aka std::mutex&}'