By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,820 Members | 1,187 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,820 IT Pros & Developers. It's quick & easy.

Restrict the class the inheritance.

P: n/a
Hi,

I have a class, i don't want any other class to be derived from that.

How can i do this?

Regards
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Neha wrote:
Hi,

I have a class, i don't want any other class to be derived from that.

How can i do this?


Just don't derive from it then.

Jul 22 '05 #2

P: n/a
Rolf Magnus wrote:
Neha wrote:

Hi,

I have a class, i don't want any other class to be derived from that.

How can i do this?

Just don't derive from it then.


no - I do not think that you can do it in C++.
"I have a class, i don't want any other class to be derived from that"
- it is a JAVA thing:

final public class A {

}

can not be "extended"/inherited from.
__________________________________________________ _____________________________
Posted Via Uncensored-News.Com - Accounts Starting At $6.95 - http://www.uncensored-news.com
<><><><><><><> The Worlds Uncensored News Source <><><><><><><><>

Jul 22 '05 #3

P: n/a
Neha escribió:
I have a class, i don't want any other class to be derived from that.


class FinalizeMyClass {
friend class MyClass;
FinalizeMyClass (); // Private constructor
};

class MyClass : virtual private FinalizeMyClass {
};

That way you can't instantiate any class derived from MyClass.

Regards.
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.