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


Please Help Members By Posting Answers For Below Questions

What are advantages of using friend classes?

642


What is called array?

624


What is the disadvantage of using a macro?

593


Where Malloc(), Calloc(), and realloc() does get memory?

614


How do I run a program in notepad ++?

608






Why do you use the namespace feature?

656


Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?

614


Difference between overloaded functions and overridden functions

584


Explain differences between new() and delete()?

622


Is c++ a good beginners programming language?

584


What is the full form nasa?

597


What do you understand by a pure virtual member function?

549


What are the advantages of using friend classes?

631


Write some differences between an external iterator and an internal iterator?

590


What is virtual base class uses?

714