Can I stop people deriving from my class?

Questions by mehulgala177   answers by mehulgala177

Showing Answers 1 - 5 of 5 Answers

jmj786

  • Sep 23rd, 2011
 

You can make your class as seal even if you want stop overriding any method inside your class just make that method as seal.

Enjoy...!

  Was this answer useful?  Yes

Kali

  • Oct 27th, 2011
 

Yes you can stop deriving the your class from other classes by using the key word 'final'. It does not allow inheritance concept.

ex:

final class Demo{
................
}

  Was this answer useful?  Yes

LordAlex

  • Nov 14th, 2011
 

No.
In Classic C++ you cannot do that.
It is possiible in Microsoft C++/CLI .NET only, but not in Visual C++.
C++/CLI has "seal","abstract" key words mentioned in above incorret answers.

  Was this answer useful?  Yes

Amit

  • Jan 6th, 2012
 

If you make all the constructor and assignment operator private of a class then logically you can prevent any other class to use your base class.

Even your derived class can inherit the base class (that have every thing private).

But you can not instanciate your derived class, so there is no meaning of inheriting a base class that have every thing private(constructor and assignment operator).

Zubair

  • Jan 18th, 2012
 

Yea It is possible in C++. Here is the code snippet.


Code
  1. span style="font-style: italic;">// Works

  2.         Derived d;  // Error

  3. "PAUSE"

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions