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


Please Help Members By Posting Answers For Below Questions

What are the types of abstraction?

557


How can you overcome the diamond problem in inheritance?

768


What is class in oop with example?

621


What is encapsulation with example?

578


What is the difference between a mixin and inheritance?

522






Why do we use encapsulation in oops?

522


How do you answer polymorphism?

577


Prepare me a program for the animation of train

2000


What is polymorphism explain?

691


Can we override main method?

607


Write a c++ program to display pass and fail for three student using static member function

2816


Can you explain polymorphism?

583


What is abstract class in oops?

600


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.

1541


Write a program to sort the number with different sorts in one program ??

1920