F
Full Decent
aclass A, B;
Can A access B's privates all the time, or only in a copy constructor?
-------and---------
This code:
#include <iostream>
class A
{
int my;
public:
A():my(0){}
void print(){std::cout<<my<<std::endl;}
void test(A x){x.my++;}
};
int main()
{
A a, b;
a.test(b);
a.print();
b.print();
}
Produces "0 0" when run.
Expected "0 1" or compile error.
--------------------
Please tell me this is one of those staying-up-late mistakes
Thanks,
Will
Can A access B's privates all the time, or only in a copy constructor?
-------and---------
This code:
#include <iostream>
class A
{
int my;
public:
A():my(0){}
void print(){std::cout<<my<<std::endl;}
void test(A x){x.my++;}
};
int main()
{
A a, b;
a.test(b);
a.print();
b.print();
}
Produces "0 0" when run.
Expected "0 1" or compile error.
--------------------
Please tell me this is one of those staying-up-late mistakes
Thanks,
Will