Can anyone tell me how to restrict inheritance in c++ with example? is their any possibility of doing it by using private mode of inheritance?
Asked
Active
Viewed 497 times
1 Answers
3
You can declare a class to be final
and therefore no other classes can derive from it. You can also specify that individual functions are final
.

Cory Kramer
- 114,268
- 16
- 167
- 218
-
1
-
I think OP wants to know if it can be done without using the `final` keyword (since it is part of C++11) – CinCout Jan 19 '15 at 13:18
-
@binaryBaBa What makes you think that they aren't using C++11? I don't see any mention of that in their question. – Cory Kramer Jan 19 '15 at 13:20
-
-
1@binaryBaBa It is the year 2015, I hope it is safe to assume that most people are using C++11 compilers, especially considering that C++14 has been finalized. – Cory Kramer Jan 19 '15 at 13:22
-
In programming, assumptions lead to doom! I so wish all the corporate projects start using C++11. – CinCout Jan 19 '15 at 13:23
-
1Questions specifically about older versions of the language should be tagged c++98, not c++. – Ferruccio Jan 19 '15 at 13:27