For example:
I have an implementation (say doSomething()) in Base class.
I want all the Derived classes to use only this implementation, and not to override the base class implementation.
How can I force this behavior in C++?
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.
If you only want to implement it in the base class, then don’t declare it
virtual, and it can’t be overridden at all.In C++11 you can declare an override
finalin a similar way to Java:In C++03 and earlier, you can’t; that’s why it was added to C++11.