How would you stop a class from class from being derived or
inherited?The constructer should not be Private,as object
instantiation should be allowed.
Answer Posted / boriska
CORRECTION to my previous post : please strike out "unless
you define similar create/destroy methods for class Derived
within Base class scope". Does not change the major idea,
just implications - but not well thought over.
The correct way is to declare class Derived as a friend to
class Base - like :
class Base
{
friend class Derived;
...
}
then Derived will be able to access Base's private
destructor. But you don't want to let that happen - as I
said - if you want to prohibit any further derivation. But
if you want to make an exception for some predefined types
derived from Base, that is the way.
Cheers and apologies.
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
what is COPY CONSTRUCTOR and what is it used for?
What is atoi in c++?
What are exceptions c++?
Explain the benefits of proper inheritance.
Explain the difference between new() and malloc() in c++?
What is the difference between an external iterator and an internal iterator? Describe an advantage of the external iterator.
What is the difference between the functions rand(), random(), srand() and randomize()?
What is the difference between struct and class?
What is the use of c++ programming language in real life?
What is stl containers in c++?
What is heap sort in c++?
Can you pass an array to a function in c++?
what Is DCS ? what i will get benefit when i did?
Is arr and &arr are same expression for an array?
What is the difference between method overloading and method overriding in c++?