- The core of this exercise is the usage of
unique_ptr
andshared_prt
. Which kind of smart pointer should be used for each of thehuman
variables? artifacts
are not shared, butpowers
are needed to track influenced people.- the
possession
pointer should be unique, the power pointers should be shared.
- You need to create a smart pointer and assign it to the
possession
variable - Use references to change the object outside of the function.
- Look up
std::make_unique
for some hints. - The type of the pointer's target object has to be put in the angled brackets and again inside the parens to define the object.
- Here is a full example:
variable = std::make_unique<int>(int{23});
- You can look through the unique_ptr reference to find a fitting function.
- Do you think
std::swap
can help you?
- You need to create a smart pointer and assign it to the
own_power
variable - Use references to change the object outside of the function.
- Look up
std::make_shared
for some hints. - The type of the pointer's target object has to be put in the angled brackets and again inside the parens to define the object.
- Here is a full example:
variable = std::make_shared<int>(int{23});
- Use references to change the object outside of the function.
- You can look through the shared_ptr reference to find a fitting function.
- Do you think
use_count
can help you?