How would you stop a class from class from being derived or
inherited.
Answer Posted / srini
#define DO_NOT_DERIVE(T) \
class NoDerive_##T { \
friend class T;
\
NoDerive_##T() {}
\
NoDerive_##T(const NoDerive_##T&) {} \
};
#define stopderiving(T) private virtual NoDerive_##T
when we derive from any class, the constructor needs to be
called, since here constructor of NoDerive calss is
private, it cannot be derived. And friendship cannot be
inherited.
usage
class finalclass : stopderiving (finalclass)
{
....
};
the other possible solution for this is making the default
constructor private.
Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
What is the difference between a mixin and inheritance?
What is static in oop?
What does enum stand for?
What is polymorphism used for?
What is the oops and benefits of oops programming?
What is the difference between inheritance and polymorphism?
What is new keyword in oops?
What is constructor in oop?
What exactly is polymorphism?
What is an advantage of polymorphism?
Whats oop mean?
Why is there no multiple inheritance?
What is the difference between abstraction and polymorphism?
How to handle exception in c++, For example in a functions i am assigning memory to some variables and also in next instructions in am dividing one variable also. If this functions generates a error while allocating memory to those variable and also while dividing the variable if i divide by zero then catch block how it will identify that this error has cone from perticular instruction
What is difference between oop and pop?