/* Friend Function */
#include<iostream.h>
#include<conio.h>
class Base2;
class Base1
{
private:
int a;
public:
void set(int b)
{
a=b;
}
friend int add(Base1,Base2);
};
class Base2
{
private:
int b;
public:
void set(int c)
{
b=c;
}
friend int add(Base1,Base2);
};
void main()
{
Base1 B1;
Base2 B2;
B1.set(100);
B2.set(200);
cout<<"\n Addition is :"<<add(B1,B2);
}
int add(Base1 B1,Base2 B2)
{
return B1.a+B2.b;
}
#include<iostream.h>
#include<conio.h>
class Base2;
class Base1
{
private:
int a;
public:
void set(int b)
{
a=b;
}
friend int add(Base1,Base2);
};
class Base2
{
private:
int b;
public:
void set(int c)
{
b=c;
}
friend int add(Base1,Base2);
};
void main()
{
Base1 B1;
Base2 B2;
B1.set(100);
B2.set(200);
cout<<"\n Addition is :"<<add(B1,B2);
}
int add(Base1 B1,Base2 B2)
{
return B1.a+B2.b;
}
No comments:
Post a Comment