-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrndFunc.cpp
More file actions
48 lines (41 loc) · 879 Bytes
/
frndFunc.cpp
File metadata and controls
48 lines (41 loc) · 879 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
#include <iostream>
#include <string>
using namespace std;
class first {
int age;
int roll;
friend void accessFirst(first);
friend void accessFirst(first f, int a);
friend class Second;
public:
first() {
age = 20;
roll = 3;
}
};
class Second {
public:
void printDetails(first f) {
cout << "age: " << f.age << endl;
cout << "roll: " << f.roll << endl;
}
};
void accessFirst(first) {
cout << "hiii" << endl;
}
void accessFirst(first f, int a) {
cout << "age: " << f.age << endl;
f.age = a;
cout << "Updated age: " << f.age << endl;
cout << "roll: " << f.roll << endl;
}
int main() {
cout << "Using friend function:" << endl;
first f1;
accessFirst(f1);
accessFirst(f1, 5);
cout << "Using friend class:" << endl;
Second s1;
s1.printDetails(f1);
return 0;
}