-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInheritance04LocalClass.cpp
51 lines (42 loc) · 1.08 KB
/
Inheritance04LocalClass.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
/*
* =====================================================================================
*
* Filename: Inheritance04LocalClass.cpp
*
* Description: Inheritance Local Classes
*
* Created: 26/07/2020
*
* Author: Maikol Guzmán mike@guzmanalan.com
* Organization: Universidad Nacional de Costa Rica
*
* =====================================================================================
*/
#include <iostream> // allows program to output data to the screen
class OtherClass {
int numberA = 3; // private property
friend class Test; // modify access
};
class Test {
int numberB; // private property
public:
int getValue() const {
struct Local {
Local(OtherClass &o)
: mOtherClass(o)
{ }
int get_other_value() {
return mOtherClass.numberA;
}
OtherClass &mOtherClass;
};
OtherClass otherClass;
Local local(otherClass);
return local.get_other_value();
}
};
int main() {
std::cout << "Welcome to the UNA!" << std::endl; // display message
Test test;
return test.getValue();
}