Re: Operator overloading and access to private members
Erik Wikstr?m wrote:
On 2008-02-16 10:48, Bo Persson wrote:
[..]
The thing is exactly that notThis is of the same type as this.
Members of a class have access to all other members of the same
class, they are siblings.
This doesn't break encapsulation, because it is the designer of the
class that decides how the class should act. You cannot do this from
the outside.
In fact it increases encapsulation, since you would have to make these
members either public or create accessor functions for then to provide
the same kind of functionality if they were not accessible from other
classes of the same type.
"... from other objects/instances of the same class/type".
That's with the existing mechanism of access specifiers. It has been
suggested before that for those data members that nobody except their
"owner" instance is allowed to access there has to be some very special
access specifier, like "secret". And the compiler would only allow
access to those inside non-static member functions and only with the
use of 'this->'. The other side has always argued that the need for
such mechanism is essentially non-existent. But the argument does pop
up every now and then. I am sure that "secret" access specifier would
only increase encapsulation, can there be any doubt about it?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask