-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfriendF.cpp
More file actions
40 lines (33 loc) · 730 Bytes
/
friendF.cpp
File metadata and controls
40 lines (33 loc) · 730 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
#include <iostream>
using namespace std;
class MyBase
{
private:
int value1;
int value2;
public:
MyBase()
{
this->value1 = 10;
this->value2 = 20;
}
void display()
{
cout << "First Value is :- " << this->value1 << endl;
cout << "Second Value is :- " << this->value2 << endl;
}
// friend function to acess private and protected data members of the class
// prototype defined in the class
friend void addValues(MyBase &B);
};
// implentation of the friend defined outside the class
void addValues(MyBase &B)
{
cout << "Total values is :- " << B.value1 + B.value2 << endl;
}
int main()
{
MyBase Base;
Base.display();
addValues(Base);
}