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

  1. Xref: sparky comp.lang.c++:15916 comp.std.c++:1511
  2. Newsgroups: comp.lang.c++,comp.std.c++
  3. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  4. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  5. Subject: Re: PROPOSAL: Hidden private parts of classes
  6. Message-ID: <1992Nov7.154137.21910@ucc.su.OZ.AU>
  7. Sender: news@ucc.su.OZ.AU
  8. Nntp-Posting-Host: extro.ucc.su.oz.au
  9. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  10. References: <1992Oct30.113234.15010@daimi.aau.dk>
  11. Date: Sat, 7 Nov 1992 15:41:37 GMT
  12. Lines: 39
  13.  
  14. In article <1992Oct30.113234.15010@daimi.aau.dk> sabroe@daimi.aau.dk (Morten Sabroe Mortensen) writes:
  15. >        Lately I've coded a lot of small libraries in C++, and been
  16. >thinking, why it's not possible to hide private parts, -it doesn't 
  17. >seem to be possible! 
  18.  
  19.  
  20.     You will note that 'private' means inaccessible to the public,
  21. not invisible. It was explicitly defined that way in the ARM.
  22.  
  23.     Having hidden data variables causes the compiler some minor
  24. inconvenience, not knowing the length. However private non-virtual
  25. member functions cause no problems (if they were allowed). These are
  26. IMHO needed so as to be able to write small helper members in
  27. the implementation, I've suggested this be allowed, a suitable 
  28. syntax does not suggest itself though.
  29.  
  30.     Having an explict 'hidden' keyword could also be done:
  31.  
  32.     class A { ..
  33.     hidden: int x;
  34.     };
  35.  
  36. where x is not just inaccessible but invisible. (But not to the programmer)
  37.  
  38.     However there IS a way to separate the implementation and
  39. the interface, namely to use an abstract class for the interface
  40.  
  41.     class X { public: f(); };
  42.     class Y : public X { public: f(); private: int x;};
  43.  
  44. This makes x truly invisible to users of X objects, but not those
  45. that must construct them. Note that this scheme will fail
  46. if downcasting is allowed :-)
  47.  
  48. -- 
  49. ;----------------------------------------------------------------------
  50.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  51.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  52. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  53.