C++11 introduces keyword final, which makes it illegal to derive from a type.
Is there a way to achieve a similar result with C++03, perhaps by making certain member functions private?
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.
There are two solutions for
C++03:First solution: private virtual friend base class with private default constructor:
Based on this answer, with the difference that template are not used – thus we can make virtual base class a friend to “final” class.
Frankly I did not like this solutions, because it adds the unnecessary virtual-ism.
All this can be enclosed in macros, to increase readability and easiness of usage:
Second solution: all constructors are private (including copy constructor). Instances of the class are created with help of friend class: