From 3232985713579510746
X-Google-Thread: f78e5,f6130266038a8c4d
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!mephistopheles.news.clara.net!news.clara.net!wagner.news.clara.net!194.159.246.34.MISMATCH!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!stump.algebra.com!devnull
From: ben04_01@freenet.de (Ben Strasser)
Newsgroups: comp.std.c++
Subject: Re: Private Methodes declared outside of the class
Date: Thu, 19 Aug 2004 18:39:09 GMT
Lines: 32
Sender: mail2news@demon.net
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <2oj8udFbd9r0U1@uni-berlin.de>
References: <2oblfaF8nds3U1@uni-berlin.de> <cfvuts$sen$1@news1nwk.SFbay.Sun.COM>
NNTP-Posting-Host: news.news.demon.net
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.demon.co.uk 1092940756 10357 158.152.254.254 (19 Aug 2004 18:39:16 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Thu, 19 Aug 2004 18:39:16 +0000 (UTC)
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803)
X-Spam-Checker-Version: SpamAssassin 2.64-mulga_r1 (2004-01-11) on 
	mulga.cs.mu.OZ.AU
X-Orig-X-Trace: news.uni-berlin.de G5+2sCVcd4EMMiX5nRirPAVFepnUMeXoncTqpyqBtbgD7t4/Ur
X-Spam-Status: No, hits=-4.2 required=5.0 tests=BAYES_00,FROM_ENDS_IN_NUMS 
	autolearn=no version=2.64-mulga_r1
X-Accept-Language: en-us, en
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id i7JId9VK027084;
	Fri, 20 Aug 2004 04:39:09 +1000 (EST)
X-Path: comp-std-cpp-robomod!not-for-mail
X-Delivered-To: std-c++@ucar.edu
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Newsgroups: comp.std.c++
Xref: g2news1.google.com comp.std.c++:1865

Steve Clamage wrote:

> If you could declare member functions outside the class definition, 
> anyone could hijack the class (for good or bad purposes), or break the 
> class invariants without anyone knowing.
No, you can't if you can only declare private methods outside of the 
class as I already explained. You can declare and define a private 
method anywhere but only call it from a public/protected method which is 
part of the interface an therefor has to be declared in the class. A 
hacking function which can not be called is no danger.

And even if it was possible if the user of the class knows it's data 
member (even if they are private) he can access them from anywhere using 
some pointer casts and assuming the internal representation of the 
class. So you will have to use pImpl or C's handle approach if you 
really want to stop people from breaking in.

Andrei Alexandrescu
 > What works against information hiding is that lookup precedes
 > protection check. That arguably is a good thing, but in C++
 > you can't easily define a member function that's just totally
 > "hidden".

Why not? I don't see a syntactical problem, I don't see a technical 
problem, I don't see a risk of breaking encapsulation.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



