Thursday, April 22, 2010

c++ - access private member of a class by member function of another class

#include"iostream"
using namespace std;
class b;
class a
{
int x;
public:
void set()
{x=30;}
void show(b);
};
class b
{
int y;
friend void a::show(b);
public:
void set()
{y=20;}

};
void a::show(b bb)
{
cout "x=" x endl;
cout "y=" bb.y;
}
int main()
{
a a1;
a1.set();
b b1;
b1.set();
a1.show(b1);
system("pause");
return 0;
}

No comments:

Post a Comment