Restrict the class the inheritance.

N

Neha

Hi,

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

How can i do this?

Regards
 
H

helge

Rolf said:
Neha wrote:




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.
 
?

=?iso-8859-1?Q?Juli=E1n?= Albo

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,147
Messages
2,570,833
Members
47,380
Latest member
AlinaBlevi

Latest Threads

Top