home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!secapl!Cookie!frank
- From: frank@Cookie.secapl.com (Frank Adams)
- Subject: Re: Const Inheritance
- Message-ID: <1992Nov05.162647.133903@Cookie.secapl.com>
- Date: Thu, 05 Nov 1992 16:26:47 GMT
- References: <1992Oct28.172457.98060@Cookie.secapl.com>
- Organization: Security APL, Inc.
- Lines: 58
-
- In article <1992Oct28.172457.98060@Cookie.secapl.com> frank@Cookie.secapl.com (Frank Adams) writes:
- >I was playing around with some ideas the other day, and came with an idea
- >which seems interesting to me. [...]
- >
- >If there were some way to inherit only the const virtual functions [...]
- >
- > class Square : public const Rectangle, public virtual Shape {...};
- >
- >
- [...]
-
- On further consideration, I think this proposal does not go far enough.
-
- What is really happening here is that, in many ways, const Foo is a separate
- class from Foo. It is different for determining which overloaded function
- to invoke, and it produces a different type when pointed to.
-
- What I propose is that const Foo be made fully a separate class from Foo.
- This would include the proposal above as an immediate consequence. It means
- that each class Foo is a subclass of const Foo, so that when we have a class
- definition:
-
- class Bar : public Foo ...
-
- we are implicitly defining a multiple inheritance matrix:
-
- const Foo
- / \
- const Bar Foo
- \ /
- \ /
- Bar
-
- Also, I am not sure whether the ARM now allows:
-
- class Foo
- {
- public:
- int bar(); // called for non-const objects
- int bar() const; // called for const objects
- }
-
- If not, this would also follow from this proposal.
-
- I believe it is now legal to define:
-
- const class Bar : public Foo ...
-
- meaning that all the members are const. For a Bar declared this way, const
- Bar would identically the same class as Bar (so a pointer to const Bar would
- be the same type as a pointer to Bar). Such a Bar would implicitly inherit
- only from const classes; so the above would be equivalent to specifying only
- const Foo as a superclass.
-
- (If cast-away-const remains in the language, this provides a way for a
- Square which inherits from const Rectangle to invoke a non-const Rectangle
- function. If some safer alternative replaces it, it would be valuable to
- have it able to support this kind of construct as well.)
-