How to stop the class to be inherited by other class.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
C++11 solution
In C++11, you can seal a class by using
finalkeyword in the definition as:To know the other uses of final, see my answer here:
C++03 solution
Bjarne Stroustrup’s code : Can I stop people deriving from my class?
Generic_lock
So we can make use of template to make the
Usable_lockgeneric enough to seal any class: