home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 15827 < prev    next >
Encoding:
Text File  |  1992-11-05  |  2.3 KB  |  69 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!secapl!Cookie!frank
  3. From: frank@Cookie.secapl.com (Frank Adams)
  4. Subject: Re: Const Inheritance
  5. Message-ID: <1992Nov05.162647.133903@Cookie.secapl.com>
  6. Date: Thu, 05 Nov 1992 16:26:47 GMT
  7. References: <1992Oct28.172457.98060@Cookie.secapl.com>
  8. Organization: Security APL, Inc.
  9. Lines: 58
  10.  
  11. In article <1992Oct28.172457.98060@Cookie.secapl.com> frank@Cookie.secapl.com (Frank Adams) writes:
  12. >I was playing around with some ideas the other day, and came with an idea
  13. >which seems interesting to me.  [...]
  14. >
  15. >If there were some way to inherit only the const virtual functions [...]
  16. >
  17. >  class Square : public const Rectangle, public virtual Shape {...};
  18. >
  19. >
  20. [...]
  21.  
  22. On further consideration, I think this proposal does not go far enough.
  23.  
  24. What is really happening here is that, in many ways, const Foo is a separate
  25. class from Foo.  It is different for determining which overloaded function
  26. to invoke, and it produces a different type when pointed to.
  27.  
  28. What I propose is that const Foo be made fully a separate class from Foo.
  29. This would include the proposal above as an immediate consequence.  It means
  30. that each class Foo is a subclass of const Foo, so that when we have a class
  31. definition:
  32.  
  33.     class Bar : public Foo ...
  34.  
  35. we are implicitly defining a multiple inheritance matrix:
  36.  
  37.     const Foo
  38.      /     \
  39.    const Bar   Foo
  40.      \     /
  41.       \   /
  42.        Bar
  43.  
  44. Also, I am not sure whether the ARM now allows:
  45.  
  46.     class Foo
  47.     {
  48.     public:
  49.     int bar();       // called for non-const objects
  50.     int bar() const; // called for const objects
  51.     }
  52.  
  53. If not, this would also follow from this proposal.
  54.  
  55. I believe it is now legal to define:
  56.  
  57.     const class Bar : public Foo ...
  58.  
  59. meaning that all the members are const.  For a Bar declared this way, const
  60. Bar would identically the same class as Bar (so a pointer to const Bar would
  61. be the same type as a pointer to Bar).  Such a Bar would implicitly inherit
  62. only from const classes; so the above would be equivalent to specifying only
  63. const Foo as a superclass.
  64.  
  65. (If cast-away-const remains in the language, this provides a way for a
  66. Square which inherits from const Rectangle to invoke a non-const Rectangle
  67. function.  If some safer alternative replaces it, it would be valuable to
  68. have it able to support this kind of construct as well.)
  69.