473,396 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

inheritance not allowed

i just wanted to know that is there any method to not allow any class
to inherit a specified class.
i.e. i hjave created a class and i dont want that anyone should inherit
it.can it b done?

Sep 27 '05 #1
6 1605
* Niks:
i just wanted to know that is there any method to not allow any class
to inherit a specified class.
i.e. i hjave created a class and i dont want that anyone should inherit
it.
Usually (for beginners, at least) that indicates a flawed design.

can it b done?


Yes, see the FAQ.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Sep 27 '05 #2
Alf P. Steinbach wrote:
* Niks:
i just wanted to know that is there any method to not allow any class
to inherit a specified class.
i.e. i hjave created a class and i dont want that anyone should inherit
it.


Usually (for beginners, at least) that indicates a flawed design.


What exactly indicates a flawed design and where? Writing a class that
does not readily allow anyone to derive classes from it at some future
date? Must all classes support derived classes? If so, wouldn't C++
class hierarchies become infinitely deep - and still not have a
concrete class to show for all that code?

One could certainly argue that "sealing" a class in C++ is unnecessary,
ineffective, gratuitous, antisocial or perhaps even immoral (the FSF's
opinion would be normative, of course). But sealing a class is really
no different than declaring parts of it "private." Both are simply
formal ways for the author of a code module to document its intended
use.

For anyone who has ever ever faced the catastrophe of having one one of
their own concrete classes being subclassed - or lived through the
ordeal of being forced to make such a misguided implementation "work" -
perhaps only those have weathered the trauma and been able to return to
their keyboards - can truly appreciate the value of a sealed class.

Greg

Sep 27 '05 #3
* Greg:
Alf P. Steinbach wrote:
* Niks:
i just wanted to know that is there any method to not allow any class
to inherit a specified class.
i.e. i hjave created a class and i dont want that anyone should inherit
it.


Usually (for beginners, at least) that indicates a flawed design.


What exactly indicates a flawed design and where?


A sealed C++ class (exluding C++ classes that are effectively sealed as a
consequence of e.g. pimpl idiom) generally says that it's so badly designed
that it's practically hopeless to derive from it and do that correctly, no
matter how much care is exercised: this class is sealed, because there's
absolutely no way to do anything reasonable with a derived class.

There are of course some exceptions.

But this is very much language dependent. C++ is built on the philosophy that
The Programmer Is Always Right, and should be allowed to do whatever, at his
or her own risk. It's not a beginner's language. In beginner's languages,
such as Java and C#, sealed classes are the norm. It's the opposite
philosophy, of the programmer being Mostly Wrong and needing stern guidance
and absolute limits (of course that applies to beginners... ;-)), and mostly
that means the programmer is meant to combine canned components, and should
not be extending or, Bush forbid, modifying their functionality.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Sep 27 '05 #4
i have created a class and i dont want that anyone should inherit
it.can it b done? the rest of the program must be able to use that
class.Just for security.

Sep 27 '05 #5
Niks wrote:

i have created a class and i dont want that anyone should inherit
it.can it b done? the rest of the program must be able to use that
class.Just for security.


As already mentioned: This is in the FAQ

http://www.parashift.com/c++-faq-lit....html#faq-23.9

--
Karl Heinz Buchegger
kb******@gascad.at
Sep 27 '05 #6
On 27 Sep 2005 01:30:51 -0700, "Niks" <nb*****@gmail.com> wrote:
i have created a class and i dont want that anyone should inherit
it.can it b done? the rest of the program must be able to use that
class.Just for security.


You'd be better off putting a comment in your code to tell the next guy not to
inherit from your class. "Security" at this level isn't possible, or even
desirable sometimes.

PS: Please type in English with proper punctuation and capitalization. "b"
isn't an English word, and "dont" should have an apostrophe in it. Go on, it's
just one extra keystroke.

-dr
Sep 28 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dave Theese | last post by:
Hello all, The example below demonstrates proper conformance to the C++ standard. However, I'm having a hard time getting my brain around which language rules make this proper... The error...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
2
by: Mr Wizard | last post by:
I am going through the front controller http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpatterns/html/ImpFrontControllerInASP.asp and all works well except when the server.transfer...
60
by: Shawnk | last post by:
Some Sr. colleges and I have had an on going discussion relative to when and if C# will ever support 'true' multiple inheritance. Relevant to this, I wanted to query the C# community (the...
4
by: Joe | last post by:
We are working on a project that requires 3rd parties (ie, consultants) to use our ASP.net webforms in a very reusable manner. The big catch is that we are not allowed to give them source. There...
4
by: tony | last post by:
Hello! Assume I have a base class called Base and a derived class called Sub. Assume all the property for the Base class can't fit exactly for the Sub class. I mean some of the property for...
11
by: John | last post by:
Hi All, Although C# has Generics, it still does not support the generic programming paradigm. Multiple inheritance is required to support real generic programming. Here is a simple design pattern...
21
by: raylopez99 | last post by:
Well, contrary to the implication in my 2000 textbook on C# (public beta version), C# does allow multiple inheritance, so long as it's serially chained as follows: class derived02 : derived01 {...
1
by: Michael Hines | last post by:
Hello, I have a class factory that supports single inheritance but it is an error if the base appears twice. e.g class Foo(hclass(h.Vector), hclass(h.List)): should raise an exception since...
0
by: Scott David Daniels | last post by:
Here are some tweaks on both bits of code: Paul McGuire wrote: .... m = for b in bases: if hasattr(b, '__mro__'): if MetaHocObject.ho in b.__mro__: m.append(b) if m:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.