Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* perform addition of two number which is private for seprate class using friend function*/
- #include<iostream>
- using namespace std;
- class B;//forward declaration
- class A
- {
- int x;
- public:
- A()//default cons
- {
- x=10;
- }
- friend void add(A,B);//declaration
- };
- class B
- {
- int y;
- public:
- B()
- {
- y=20;
- }
- friend void add(A,B);//declaration
- };
- void add(A a1,B b1)
- {
- cout<<"Sum of two diff class private member is "<<a1.x+b1.y;
- }
- int main()
- {
- A a1;
- B b1;
- add(a1,b1);
- }
Advertisement
Add Comment
Please, Sign In to add comment