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?
4 Answers
+ 1
It seems to work:
https://code.sololearn.com/cJ1Q1BdCKOZg/?ref=app
+ 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?
+ 1
Thank you all. I found the fault. I missed a } bracket at the end of a function definition.