Cpp-Primer icon indicating copy to clipboard operation
Cpp-Primer copied to clipboard

Answer to Exercise 13.16 might be wrong

Open MRamez opened this issue 9 years ago • 5 comments

In the answer to exercise 13.16 it is stated that "the three Output are the same", but I think this is wrong, because although copy constructor is not called when f() is called, the copy constructor is called when we initialize b from a, and also c from b. So, a, b, and c have different serial numbers. The code provided in exercise 13.17 for exercise 13.16 also prints three different numbers (10, 11, and 12).

MRamez avatar Sep 03 '15 15:09 MRamez

I agree with you.

  • ex13.15: copy constructor will be called five times.
  • ex13.16: copy constructor will be called twice.

That's the difference.

ivechan avatar Aug 21 '16 03:08 ivechan

I think so, I want to ask this question too.

tp7309 avatar Aug 27 '16 00:08 tp7309

I also agree with you:)

huang-jl avatar Jun 11 '19 15:06 huang-jl

I agree with you. I have test it in VS2019 and the result is (10, 11 and 12).

SnailForce avatar Oct 30 '19 12:10 SnailForce

Right! I also test in VS and it does output different answers!

Allenyhf avatar Apr 10 '21 12:04 Allenyhf