mirror of
https://github.com/dancojocaru2000/y3s2-cciot-hw.git
synced 2025-02-22 17:09:35 +02:00
Solved Lab1 Slide 13
This commit is contained in:
parent
f1a2332a7d
commit
e90300843f
1 changed files with 37 additions and 0 deletions
|
@ -26,3 +26,40 @@ Try this:
|
||||||
### Solution
|
### Solution
|
||||||
|
|
||||||
See [slide11.cpp](./slide11.cpp).
|
See [slide11.cpp](./slide11.cpp).
|
||||||
|
|
||||||
|
## Slide 13
|
||||||
|
|
||||||
|
### Problem
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
class Human
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Human();
|
||||||
|
~Human();
|
||||||
|
private:
|
||||||
|
std::string name;
|
||||||
|
int age;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
Try this:
|
||||||
|
|
||||||
|
1. Try to retrieve the data from all humans and print it to the screen.
|
||||||
|
2. Try to find a workaround for the errors (if you don’t see any errors you’re doing something wrong).
|
||||||
|
|
||||||
|
### Solution
|
||||||
|
|
||||||
|
1. Because the `name` and `age` fields are private, they cannot be accessed.
|
||||||
|
2. A solution would be creating getters for them:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
class Human
|
||||||
|
{
|
||||||
|
...
|
||||||
|
public:
|
||||||
|
const std::string& getName();
|
||||||
|
const int& getAge();
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue