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

Reads in the size of a square from the screen; 2. Prints a hollow square of that size out of “-“, “|” and blanks on screen; 3. Prints the same hollow square onto a text file. Your program should work for squares of all side sizes between 1 and 20. --- │ │ │ │ │ │ ---

1750


Explain the use of this pointer?

738


Why c++ is created?

654


Can you pass an array to a function in c++?

627


Is c++ a good first language to learn?

657






What are multiple inheritances (virtual inheritance)?

676


What is the meaning of c++?

636


What is the full form of dos?

671


What is c++ array?

636


Write a program using merge () function to combine the elements of array x[ ] and y[ ] into array z[ ].

688


Explain the advantages of using friend classes.

695


Should the this pointer can be used in the constructor?

642


How would you differentiate between a pre and post increment operators while overloading?

735


When do we use copy constructors?

685


How many types of scopes are there in c++?

662