From e90300843fddcf2ea3c180b0b510934c80b8b0f3 Mon Sep 17 00:00:00 2001 From: Dan Cojocaru Date: Sun, 13 Mar 2022 16:12:46 +0200 Subject: [PATCH] Solved Lab1 Slide 13 --- Lab1/README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Lab1/README.md b/Lab1/README.md index f990c30..1e22008 100644 --- a/Lab1/README.md +++ b/Lab1/README.md @@ -26,3 +26,40 @@ Try this: ### Solution 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(); +}; +``` +