forked from hsf-training/cpluspluscourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.cpp
33 lines (26 loc) · 1.08 KB
/
functions.cpp
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
/* Tasks:
* 1. Check out Structs.h. It defines two structs that we will work with.
* FastToCopy
* SlowToCopy
* They are exactly what their name says, so let's try to avoid copying the latter.
* 2. Using "printFiveCharacters()" as an example, write a function that prints the first five characters of "SlowToCopy".
* Call it in main().
* 3. Try passing by copy and passing by reference, see the difference.
* 4. When passing by reference, ensure that your "printFiveCharacters" cannot inadvertently modify the original object.
* To test its const correctness, try adding something like
* argument.name[0] = 'a';
* to your print function.
* Try both with and without const attributes in your print function's signature.
*/
#include "Structs.h" // The data structs we will work with
#include <iostream> // For printing
void printFiveCharacters(FastToCopy argument) {
std::cout << argument.name << "\n";
}
int main() {
FastToCopy fast = {"abcdef"};
printFiveCharacters(fast);
SlowToCopy slow = {"ghijkl"};
// print it here
return 0;
}