-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfriendclass.cpp
More file actions
47 lines (37 loc) · 743 Bytes
/
friendclass.cpp
File metadata and controls
47 lines (37 loc) · 743 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
#include <iostream>
using namespace std;
class Student {
private:
string name;
int roll;
public:
Student(string n, int r) {
name = n;
roll = r;
}
// Declare Display as a friend class
friend class Display;
~Student() {
cout << "Destructor called for Student: " << name << endl;
}
};
// Friend class
class Display {
public:
void showDetails(Student s) {
cout << "Name: " << s.name << endl;
cout << "Roll No: " << s.roll << endl;
}
};
int main() {
string name;
int roll;
cout << "Enter name: ";
cin >> name;
cout << "Enter roll number: ";
cin >> roll;
Student s(name, roll);
Display d;
d.showDetails(s);
return 0;
}