-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq5.cpp
55 lines (46 loc) · 1.11 KB
/
q5.cpp
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
55
#include <iostream>
using namespace std;
class A;
class B;
class C;
// Friend function declaration
void displayData(const A& a, const B& b, const C& c);
class A {
private:
int priv_a;
protected:
int pro_a;
public:
A(int p, int pr) : priv_a(p), pro_a(pr) {}
friend void displayData(const A& a, const B& b, const C& c);
};
class B {
private:
int priv_b;
protected:
int pro_b;
public:
B(int p, int pr) : priv_b(p), pro_b(pr) {}
friend void displayData(const A& a, const B& b, const C& c);
};
class C {
private:
int priv_c;
protected:
int pro_c;
public:
C(int p, int pr) : priv_c(p), pro_c(pr) {}
friend void displayData(const A& a, const B& b, const C& c);
};
void displayData(const A& a, const B& b, const C& c) {
cout << "Class A - Private: " << a.priv_a << ", Protected: " << a.pro_a << endl;
cout << "Class B - Private: " << b.priv_b << ", Protected: " << b.pro_b << endl;
cout << "Class C - Private: " << c.priv_c << ", Protected: " << c.pro_c << endl;
}
int main() {
A a(10, 20);
B b(30, 40);
C c(50, 60);
displayData(a, b, c);
return 0;
}