#include <iostream>
using namespace std;
class B;
class A
{int a;
public:
void set_val (int x ){
a=x;}
void swap1(A ,B );};
class B{
int b;
public:
friend void A::swap1 (A ,B );
void set_val (int y ){
b=y;}};
void A:: swap1 (A obj1, B obj2)
{int temp;
temp =obj1.a ;
obj1 . a=obj2.b;
obj2.b = temp;
cout << "The value of a :"<< obj1.a << endl;
cout << "The value of b :"<< obj2.b << endl;}
int main()
{ A obj;
B o;
obj.set_val (5);
o.set_val(2);
obj.swap1(obj,o);
return 0;
}
using namespace std;
class B;
class A
{int a;
public:
void set_val (int x ){
a=x;}
void swap1(A ,B );};
class B{
int b;
public:
friend void A::swap1 (A ,B );
void set_val (int y ){
b=y;}};
void A:: swap1 (A obj1, B obj2)
{int temp;
temp =obj1.a ;
obj1 . a=obj2.b;
obj2.b = temp;
cout << "The value of a :"<< obj1.a << endl;
cout << "The value of b :"<< obj2.b << endl;}
int main()
{ A obj;
B o;
obj.set_val (5);
o.set_val(2);
obj.swap1(obj,o);
return 0;
}
Output:
Comments
Post a Comment