Although unique_ptrs cannot be copied, in § 12.1.5 (p. 471) we wrote a clone function that returned a unique_ptr by value. Explain why that function is legal and how it works.
§ 12.1.5 (p. 471)
Exercise 12.16
Compilers don’t always give easy-to-understand error messages if we attempt to copy or assign a unique_ptr. Write a program that contains these errors to see how your compiler diagnoses them.
Exercise 12.17
Which of the following unique_ptr declarations are illegal or likely to result in subsequent program error? Explain what the problem is with each one.
int ix = 1024, *pi = &ix, *pi2 = new int(2048);typedef unique_ptrIntP;
(a) IntP p0(ix);
(b) IntP pl(pi);
(c) IntP p2(pi2);
(d) IntP p3(&ix);
(e) IntP p4(new int(2048));
(f) IntP p5(p2.get());
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.