fork download
  1. #include <mutex>
  2. #include <vector>
  3.  
  4. std::mutex protectBuffer;
  5. std::vector<int> somevector;
  6.  
  7. void myfunction(int data)
  8. {
  9. std::lock_guard<std::mutex> (protectBuffer);
  10. somevector.push_back(data);
  11. }
  12.  
  13. int main()
  14. {
  15. myfunction(3);
  16. }
  17.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘void myfunction(int)’:
prog.cpp:9:47: error: no matching function for call to ‘std::lock_guard<std::mutex>::lock_guard()’
     std::lock_guard<std::mutex> (protectBuffer);
                                               ^
prog.cpp:9:47: note: candidates are:
In file included from prog.cpp:1:0:
/usr/include/c++/4.8/mutex:416: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.8/mutex:416:7: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/4.8/mutex:413: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.8/mutex:413:16: note:   candidate expects 1 argument, 0 provided
stdout
Standard output is empty