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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!cs.utexas.edu!wupost!cs.uiuc.edu!sparc0b!pjl
  3. From: pjl@cs.uiuc.edu (Paul Lucas)
  4. Subject: Re: Public access to private data member
  5. Message-ID: <Bz3xH1.9uq@cs.uiuc.edu>
  6. Sender: news@cs.uiuc.edu
  7. Organization: University of Illinois at Urbana-Champaign
  8. References: <28575.9212111556@louis.ecs.soton.ac.uk>
  9. Date: Fri, 11 Dec 1992 18:17:24 GMT
  10. Lines: 42
  11.  
  12. In <28575.9212111556@louis.ecs.soton.ac.uk> Stuart Maclean <S.D.Maclean@ecs.soton.ac.uk> writes:
  13.  
  14. >Hi all, I'm new to C++ and am wading through Lippman's Primer. I am
  15. >puzzled by a certain example. The basis of my query is easily seen
  16. >with some code. Apologies if this is a FAQ.
  17.  
  18. >// a Screen Class declaration.
  19.  
  20. >class Screen
  21. >{
  22. >  short height;
  23. >  short width;
  24. >  char *cursor;
  25. >  char *screen;
  26.  
  27. >public 
  28. >  ......
  29. >  void copy ( Screen& );
  30. >}
  31.  
  32. >now, the copy function is implemented thus:
  33.  
  34. >void Screen::copy( Screen& s )
  35. >{
  36. >  delete screen;
  37. >  height = s.height;
  38. >  width = s.width;
  39.  
  40. >  blah blah blah
  41. >}
  42.  
  43. >My question is;
  44. >  Why are the data members s.height and s.width accessible to copy,
  45. >  even though both height and width are declared private. Is
  46. >  it just because s happens to be of the same class as the target
  47. >  object ??
  48.  
  49. *****>    Yes.
  50. -- 
  51.     - Paul J. Lucas                University of Illinois    
  52.       AT&T Bell Laboratories        at Urbana-Champaign
  53.       Naperville, IL            pjl@cs.uiuc.edu
  54.