I'm trying to write a class include a public thread object, and finally I want to access this thread ouside the class, but there are some errors, why?
The class defined as:
class scoped_thread { public: std::thread t; explicit scoped_thread(std::thread t_) : t(std::move(t_)) { if (!t.joinable()) throw std::logic_error("No thread"); } ~scoped_thread() { // t.join(); } scoped_thread(scoped_thread const &) = delete; scoped_thread & operator = (scoped_thread const &) = delete; };
and I'm try to access thread member:
scoped_thread th(std::thread(f)); th.t.join();
At last, the error is:
error: request for member 't' in 'th', which is of non-class type 'scoped_thread(std::thread)'
https://stackoverflow.com/questions/66864184/c-request-for-thread-member-for-class-cannot-be-access March 30, 2021 at 10:56AM
没有评论:
发表评论