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
What is the purpose of ios::basefield in the following statement?
How are Structure passing and returning implemented by the compiler?
Define namespace in c++?
What is the difference between map and hashmap in c++?
Why do we use string in c++?
Difference between a copy constructor and an assignment operator.
Explain how would you handle a situation where you cannot call the destructor of a local explicitly?
How a modifier is similar to mutator?
Is c++ low level?
Does dev c++ support c++ 11?
What is the purpose of templates in c++?
What is a v-table?
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?
How would you find out if a linked-list is a cycle or not?
What is the difference between containment and delegation?