Given the following sketch of a class, write a copy constructor that copies all the members. Your constructor should dynamically allocate a new string (§ 12.1.2, p. 458) and copy the object to which ps points, rather than copying ps itself.
class HasPtr {public: HasPtr(const std::string &s = std::string()): ps(new std::string(s)), i(0) { }private: std::string *ps; int i;};§ 12.1.2 (p. 458)
Exercise 12.6
Write a function that returns a dynamically allocated vector of ints. Pass that vector to another function that reads the standard input to give values to the elements. Pass the vector to another function to print the values that were read. Remember to delete the vector at the appropriate time.
Exercise 12.7
Redo the previous exercise, this time using shared_ptr.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.