fork(4) download
  1. #include <mutex>
  2.  
  3. class Foo
  4. {
  5. private:
  6. std::mutex lock_;
  7.  
  8. public:
  9. Foo() = default;
  10. ~Foo() = default;
  11.  
  12. void bad();
  13. void good();
  14. };
  15.  
  16. void Foo::bad()
  17. {
  18. std::lock_guard<std::mutex>(lock_);
  19. }
  20.  
  21. void Foo::good()
  22. {
  23. std::lock_guard<std::mutex>(this->lock_);
  24. }
  25.  
  26. int main()
  27. {
  28. return 0;
  29. }
  30.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function 'void Foo::bad()':
prog.cpp:18:36: error: no matching function for call to 'std::lock_guard<std::mutex>::lock_guard()'
   std::lock_guard<std::mutex>(lock_);
                                    ^
In file included from prog.cpp:1:0:
/usr/include/c++/5/mutex:379:7: note: candidate: 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++/5/mutex:379:7: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/5/mutex:376:16: note: candidate: 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++/5/mutex:376:16: note:   candidate expects 1 argument, 0 provided
stdout
Standard output is empty