0

How to code std::lock_guard<std::mutex> l(m)?

template<typename T> class threadsafe_stack { // Sharing data between threads private: std::stack<T> data; mutable std::mutex m; public: ... std::lock_guard<std::mutex> l(m); I get the error in Sololearn: 'm' is no type. What is here wrong coded, or is it a problem of the Sololearn C++ Compiler?

12th May 2019, 4:48 PM
Mini Coe
Mini Coe - avatar
4 ответов
12th May 2019, 5:57 PM
Paul
+ 1
Yes. 'm' is a private member of the class threadsafe_stack. The std::lock_guard<std::mutex> l(m); is a function call inside this class. Why is it not compilable without this error?
14th May 2019, 9:18 PM
Mini Coe
Mini Coe - avatar
+ 1
Thank you all. I found the fault. I missed a } bracket at the end of a function definition.
14th May 2019, 9:46 PM
Mini Coe
Mini Coe - avatar