Topic: Encapsulation within Class
Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Sat, 17 Sep 1994 07:04:32 GMT Raw View
bruce@betsy.gps.caltech.edu (Bruce Worden) writes:
>Does a member function of
>a class have legal access to the private members of all objects of
>that class?
Yes. In C++, protection applies to classes, not to objects.
--
Fergus Henderson - fjh@munta.cs.mu.oz.au
Author: bruce@betsy.gps.caltech.edu (Bruce Worden)
Date: 14 Sep 1994 00:37:00 GMT Raw View
The following compiles just fine with two different compilers:
class R {
public:
void dd(R *rp) { rp->a = 5; }
private:
int a;
};
int main() {
R r;
R r2;
r.dd(&r2);
return 0;
}
which surprises me. Maybe it shouldn't. Does a member function of
a class have legal access to the private members of all objects of
that class?
--------------------------------------------------------------------------
C. Bruce Worden bruce@seismo.gps.caltech.edu
252-21 Seismological Laboratory, Caltech, Pasadena, CA 91125