home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!pipex!warwick!bham!bhamvx!mccauleyba
- From: mccauleyba@vax1.bham.ac.uk (Brian McCauley)
- Subject: Re: Public access to private data member
- Sender: usenet@rs6000.bham.ac.uk (USENET News Service)
- Message-ID: <1992Dec11.181016.1@vax1.bham.ac.uk>
- Date: Fri, 11 Dec 1992 18:10:16 GMT
- Lines: 34
- References: <28575.9212111556@louis.ecs.soton.ac.uk>
- Organization: University of Birmingham
-
- In article <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.
- It is.
-
- [ class def'n deleted ]
-
- > 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 in C++ classes (not objects) have private members. The reasoning is
- that privacy is there to give the class implementor the freedom to
- re-implement. This may be a less than totally OO standpoint but
- pragmatically it works well.
- --
- \\ ( ) No Bullshit! | Email: B.A.McCauley@bham.ac.uk
- . _\\__[oo from | Voice: +44 21 471 3789 (home)
- .__/ \\ /\@ /~) /~[ /\/[ | Fax: +44 21 625 2175 (work)
- . l___\\ /~~) /~~[ / [ | Snail: 197 Harborne Lane,
- # ll l\\ ~~~~ ~ ~ ~ ~ | Birmingham, B29 6SS, UK
- ###LL LL\\ (Brian McCauley) | ICBM: 52.5N 1.9W
-