forked from czarny247/kurs_cpp_lato_2019
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost-test.txt
More file actions
67 lines (58 loc) · 1.19 KB
/
post-test.txt
File metadata and controls
67 lines (58 loc) · 1.19 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
1. What will be printed on the screen? What kind of problems can you see?
```cpp
#include <string>
#include <iostream>
struct A {
void setNumber(int n);
int getNumber() const;
private:
int number;
};
class B : public A {
void setText(std::string s);
std::string getText() const;
private:
std::string text;
};
int main() {
A* obj = new B();
obj->setNumber(5);
obj->setText("hi");
std::cout << obj->getNumber()
<< obj->getText()
<< '\n';
}
```
https://ideone.com/dYHume
2. What will be printed on the screen? What kind of problems can you see?
```cpp
#include <string>
#include <iostream>
class A {
public:
A() {}
~A() {}
virtual std::string whoAreYou() {
return "I'm class A";
}
};
class B : public A {
public:
B() {}
~B() {}
std::string whoAreYou() {
return "I'm class B";
}
};
int main() {
A a;
B b;
B* bp = new A();
A& ar = b;
std::cout << a.whoAreYou() << '\n';
std::cout << b.whoAreYou() << '\n';
std::cout << bp.whoAreYou() << '\n';
std::cout << ar.whoAreYou() << '\n';
}
```
https://ideone.com/C964oW