fork(1) download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cmath>
  4. #include <string>
  5. #include <thread>
  6. #include <mutex>
  7. using namespace std;
  8.  
  9. struct Foo {
  10. private:
  11. int _i = 0;
  12. std::mutex _mutex;
  13. public:
  14. int f() const
  15. {
  16. std::lock_guard<std::mutex> locker(_mutex);
  17. return _i;
  18. }
  19.  
  20. };
  21.  
  22. int main()
  23. {
  24. Foo foo;
  25. foo.f();
  26. cin.get();
  27. return 0;
  28. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
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&}'
stdout
Standard output is empty