0

RAII for thread

Hi I just tried to use inherit thread to ensure that if someone forget to join thread object, destructor should detach it. Refer below code and it would be helpful if you can suggest why it is not compiling https://code.sololearn.com/ca04A25a247A

15th Apr 2021, 9:11 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 odpowiedzi
+ 1
You have to explicitly inherit the base constructors if you don't want to create your own. Add using thread::thread; in the public part of the class mythread
15th Apr 2021, 12:33 PM
Anthony Maina
Anthony Maina - avatar
0
Thank you. Yes, it is working if I add thread constructor.... But refer below code: https://code.sololearn.com/c8a8a23a23a2/#cpp Here, without adding constructor into mylist, it works. Is it like we need to add constructor also if destructor is defined by us?
15th Apr 2021, 1:24 PM
Ketan Lalcheta
Ketan Lalcheta - avatar