home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 17818 < prev    next >
Encoding:
Text File  |  1992-12-11  |  1.7 KB  |  46 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!pipex!warwick!bham!bhamvx!mccauleyba
  3. From: mccauleyba@vax1.bham.ac.uk (Brian McCauley)
  4. Subject: Re: Public access to private data member
  5. Sender: usenet@rs6000.bham.ac.uk (USENET News Service)
  6. Message-ID: <1992Dec11.181016.1@vax1.bham.ac.uk>
  7. Date: Fri, 11 Dec 1992 18:10:16 GMT
  8. Lines: 34
  9. References: <28575.9212111556@louis.ecs.soton.ac.uk>
  10. Organization: University of Birmingham
  11.  
  12. In article <28575.9212111556@louis.ecs.soton.ac.uk>, Stuart Maclean <S.D.Maclean@ecs.soton.ac.uk> writes:
  13. > Hi all, I'm new to C++ and am wading through Lippman's Primer. I am
  14. > puzzled by a certain example. The basis of my query is easily seen
  15. > with some code. Apologies if this is a FAQ.
  16. It is.                    
  17.  
  18.   [ class def'n deleted ]
  19.  
  20. > void Screen::copy( Screen& s )
  21. > {
  22. >   delete screen;
  23. >   height = s.height;
  24. >   width = s.width;
  25. >   blah blah blah
  26. > }
  27. > My question is;
  28. >   Why are the data members s.height and s.width accessible to copy,
  29. >   even though both height and width are declared private. Is
  30. >   it just because s happens to be of the same class as the target
  31. >   object ??
  32.  
  33. Yes in C++ classes (not objects) have private members. The reasoning is
  34. that privacy is there to give the class implementor the freedom to
  35. re-implement. This may be a less than totally OO standpoint but
  36. pragmatically it works well.
  37. -- 
  38.     \\   ( )    No Bullshit!     |  Email: B.A.McCauley@bham.ac.uk   
  39.  .  _\\__[oo        from         |  Voice: +44 21 471 3789 (home)
  40. .__/  \\ /\@    /~)  /~[   /\/[  |    Fax: +44 21 625 2175 (work)
  41. .  l___\\      /~~) /~~[  /   [  |  Snail: 197 Harborne Lane,
  42.  # ll  l\\    ~~~~ ~   ~ ~    ~  |         Birmingham, B29 6SS, UK
  43. ###LL  LL\\   (Brian McCauley)   |   ICBM: 52.5N 1.9W
  44.