-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBasicInheritance.cpp
More file actions
46 lines (38 loc) · 1.12 KB
/
BasicInheritance.cpp
File metadata and controls
46 lines (38 loc) · 1.12 KB
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
/*
* =====================================================================================
*
* Filename: example_01.cpp
*
* Description: Basic of inheritance
*
* Created: 26/07/2020
*
* Author: Maikol Guzmán mikeguzman@gmail.com
* Organization: Universidad Nacional de Costa Rica
*
* =====================================================================================
*/
#include <iostream> // allows program to output data to the screen
struct Base {
Base(const int number) : memberNumber(number) {
}
void doSomething() {
memberNumber += 2;
}
int memberNumber = 0;
};
struct Derived : Base {
Derived() : Base(5) { }
void doSomethingElse() {
++memberNumber;
}
};
// function main begins program execution
int main(int argc, const char *argv[]) {
std::cout << "Welcome to the UNA!" << std::endl; // display message
Derived derived;
derived.doSomething();
derived.doSomethingElse();
std::cout << derived.memberNumber << '\n'; // What is printed?
return 0; // indicate that program ended successfully
} // end function main