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 are the types of abstraction?
How can you overcome the diamond problem in inheritance?
What is class in oop with example?
What is encapsulation with example?
What is the difference between a mixin and inheritance?
Why do we use encapsulation in oops?
How do you answer polymorphism?
Prepare me a program for the animation of train
What is polymorphism explain?
Can we override main method?
Write a c++ program to display pass and fail for three student using static member function
Can you explain polymorphism?
What is abstract class in oops?
hi, this is raju,iam studying b.tech 2nd year,iam want know about group1 and group2 details, and we can studying without going to any instutions? please help me.
Write a program to sort the number with different sorts in one program ??