Hi any one let me know How to make class not derivable at all. is there any way? please let me know. regards Hara
+5
A:
See this explanation on how do to it, and why it might not be a good idea, by Bjarne Stroustrup (creator of C++ himself).
Jergason
2009-10-24 03:51:06
nice. thanks a lot
Haranadh Gupta
2009-10-24 03:53:40
+4
A:
If your class has a private constructor, there is no way for a derived class to be instantiated.
See "How can I set up my class so it won't be inherited from?" on the C++ FAQ Lite.
Mark Rushakoff
2009-10-24 03:51:26
Just making constructor private is not enough. refer Link provided by "Charles Salvia". Thanks to both of you. :)
Haranadh Gupta
2010-04-15 14:55:11
+3
A:
Make the ctor(s) private.
class not_derivable { private: not_derivable(){} };
class derived : public not_derivable {};
int main() { derived d; // diagnostic }
or the dtor:
class not_derivable { private: ~not_derivable(){} };
class derived : public not_derivable {};
int main() { not_derivable *nd = new not_derivable; derived d; //diagnostic }
dirkgently
2009-10-24 03:52:46