You are working with a data object that stores values read from input.
This data must be accessed by both main() and another function.
If the object is owned by only one place, it may be destroyed too early.
To prevent this, ownership must be shared.
Your task is to use std::shared_ptr so that both main() and a function own the same object, ensuring the data remains valid until both are done using it.
What You Must Do:
std::shared_ptrProgram Flow:
NN integersN values into the objectmain()
Example Input:
3
10 20 30
Example Output:
Data created
Printed in function
10 20 30
Printed in main
10 20 30
Data destroyed
Constraints:
N ranges from 1 to 100std::shared_ptr
Input
3 10 20 30
Expected Output
Data created Printed in function 10 20 30 Printed in main 10 20 30 Data destroyed