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 different between oops and c++
I have One image (means a group photo ) how to split the faces only from the image?............ please send the answer nagadurgaraju@gmail.com thanks in advace...
What is a class and object?
Give two or more real cenario of virtual function and vertual object
Why interface is used?
What is inheritance in simple words?
Can main method override?
What is the advantage of oop over procedural language?
What is abstraction with example?
What is interface in oop?
What is the renewal class?
Why do we use oops?
What are the two different types of polymorphism?
What is the importance of oop?
What is polymorphism explain?