home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!cs.utexas.edu!wupost!cs.uiuc.edu!sparc0b!pjl
- From: pjl@cs.uiuc.edu (Paul Lucas)
- Subject: Re: Public access to private data member
- Message-ID: <Bz3xH1.9uq@cs.uiuc.edu>
- Sender: news@cs.uiuc.edu
- Organization: University of Illinois at Urbana-Champaign
- References: <28575.9212111556@louis.ecs.soton.ac.uk>
- Date: Fri, 11 Dec 1992 18:17:24 GMT
- Lines: 42
-
- In <28575.9212111556@louis.ecs.soton.ac.uk> Stuart Maclean <S.D.Maclean@ecs.soton.ac.uk> writes:
-
- >Hi all, I'm new to C++ and am wading through Lippman's Primer. I am
- >puzzled by a certain example. The basis of my query is easily seen
- >with some code. Apologies if this is a FAQ.
-
- >// a Screen Class declaration.
-
- >class Screen
- >{
- > short height;
- > short width;
- > char *cursor;
- > char *screen;
-
- >public
- > ......
- > void copy ( Screen& );
- >}
-
- >now, the copy function is implemented thus:
-
- >void Screen::copy( Screen& s )
- >{
- > delete screen;
- > height = s.height;
- > width = s.width;
-
- > blah blah blah
- >}
-
- >My question is;
- > Why are the data members s.height and s.width accessible to copy,
- > even though both height and width are declared private. Is
- > it just because s happens to be of the same class as the target
- > object ??
-
- *****> Yes.
- --
- - Paul J. Lucas University of Illinois
- AT&T Bell Laboratories at Urbana-Champaign
- Naperville, IL pjl@cs.uiuc.edu
-