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
What is the difference between map and hashmap in c++?
What are 2 ways of exporting a function from a dll?
What is a down cast?
What are its advantages and disadvantages of multiple inheritances (virtual inheritance)?
Which is better c++ or java?
Define linked lists with the help of an example.
What is ofstream c++?
Name four predefined macros.
What is c++ and its uses?
What is the oldest programming language?
How should a contructor handle a failure?
What is new in c++?
Can a program run without main function?
What is the importance of mutable keyword?
List the issue that the auto_ptr object handles?