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

Mms, thanks for arising my curiosity on the subject -
actually, there is very elegant solution to make class no
inheritable and allow it on stack. The idea is to virtually
inherit from base class with private destructor. Virtual
inheritance will force derived classes to call virtual base
destructor first, and it would be impossible because its is
private. Much better than solution I described, must admit.
Ok, here is the link with very good description :
http://www.codeguru.com/cpp/cpp/cpp_mfc/stl/article.php/c4143/

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the various arithmetic operators in c++?

576


What is an adaptor class or wrapper class in c++?

609


What are enumerations?

661


What is the best free c++ compiler for windows?

592


What is the best c++ compiler?

596






Is std :: string immutable?

567


What are pointer-to-members? Explain.

636


Explain the difference between overloading and overriding?

616


Why do we use classes in programming?

578


What is a static member?

618


Differentiate between structure and class in c++.

604


Can non-public members of another instance of the class be retrieved by the method of the same class?

610


What is the best ide for c++?

576


What is & in c++ function?

597


What is the array and initializing arrays in c++?

510