Kvíz: Kopie, nebo reference?
1#include <iostream>
2#include <string>
3#include <vector>
4
5struct Prisera {
6 std::string jmeno;
7 int zivoty;
8};
9
10int main() {
11 std::vector<Prisera> prisery = {{"Skřet", 30}, {"Ork", 50}};
12
13 for (Prisera prisera : prisery) {
14 prisera.zivoty -= 10;
15 }
16 for (Prisera& prisera : prisery) {
17 prisera.zivoty -= 5;
18 }
19 Prisera prvni = prisery[0];
20 prvni.zivoty = 0;
21
22 std::cout << prisery[0].zivoty << " " << prisery[1].zivoty << std::endl;
23 return 0;
24}