tom_usenet
Tue Dec 16 13:31:03 CST 2003
On Tue, 16 Dec 2003 11:12:43 -0800, "fh1996" <fh1996@yahoo.com> wrote:
>There are two instances, Obj1 and Obj2, of the same class. What is a
>simplest way to access private or protected data of Obj1 from within Obj2?
If the two objects are of the same class, then they can access private
and protected members of each other. e.g.
class Foo
{
int i;
public:
Foo()
:i(0)
{
}
void modifyOtherFoo(Foo& f)
{
//access private parts of other Foo
f.i = 10;
}
};
int main()
{
Foo f1, f2;
f1.modifyOtherFoo(f2);
}
Tom
C++ FAQ:
http://www.parashift.com/c++-faq-lite/
C FAQ:
http://www.eskimo.com/~scs/C-faq/top.html