-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcomplicated.cpp
More file actions
55 lines (54 loc) · 799 Bytes
/
complicated.cpp
File metadata and controls
55 lines (54 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//menber of one class and friend of n classes
using namespace std;
#include<iostream>
//addition member of complex class //also friend of n classes
class integer;
class complex
{
int a,b;
public:
void get()
{
cin>>a>>b;
}
void display()
{
cout<<a<<" + i"<<b;
}
//no need to send object of complex class
void addition(integer in);
};
class integer
{
int n;
public:
void get()
{
cin>>n;
}
void display()
{
cout<<n;
}
//we have to use classname complex here
friend void complex::addition(integer in);
};
//we never write friend outside
void complex::addition(integer in)
{
a=a+in.n;
b=b+in.n;
}
int main()
{
complex ob;
integer ob1;
ob.get();
ob1.get();
ob.display();
ob1.display();
ob.addition(ob1);
cout<<endl;
ob.display();
return 0;
}