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 is the purpose of ios::basefield in the following statement?

889


How are Structure passing and returning implemented by the compiler?

700


Define namespace in c++?

725


What is the difference between map and hashmap in c++?

661


Why do we use string in c++?

596






Difference between a copy constructor and an assignment operator.

661


Explain how would you handle a situation where you cannot call the destructor of a local explicitly?

621


How a modifier is similar to mutator?

739


Is c++ low level?

694


Does dev c++ support c++ 11?

651


What is the purpose of templates in c++?

657


What is a v-table?

753


what is the difference between linear list linked representaion and linked representation? what is the purpose of representing the linear list in linked represention ? is it not avoiding rules of linear represention?

1837


How would you find out if a linked-list is a cycle or not?

642


What is the difference between containment and delegation?

822