Home > Archive > VC Language > January 2006 > private member access
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
private member access
|
|
| Peter Carlson 2006-01-24, 7:07 pm |
| I know this is a very simple c++ question, but I thought that private
data members were only accessible inside the class. So why is A.x
accessible to the function IsA?
class A {
public:
bool IsA(A &a) {
return (a.x == x) ? true : false;
}
private:
int x;
};
Peter
| |
| John Carson 2006-01-24, 7:07 pm |
| "Peter Carlson" <peter@h_o_w_u_d_o_d_a_t.com> wrote in message
news:OqP8rHUIGHA.3100@tk2msftngp13.phx.gbl
> I know this is a very simple c++ question, but I thought that private
> data members were only accessible inside the class. So why is A.x
> accessible to the function IsA?
>
> class A {
> public:
> bool IsA(A &a) {
> return (a.x == x) ? true : false;
> }
> private:
> int x;
> };
>
>
> Peter
Because access rights are class-wide, not object-wide. Thus if you have
A a1, a2;
then a1 has access rights to a2 and vice versa.
--
John Carson
| |
| Simon Trew 2006-01-25, 7:23 pm |
| Because ISA is a member of the class, and so has access to the private data
of *any* instance of that class.
S.
|
|
|
|
|