Mooophy / Cpp-Primer

C++ Primer 5 answers
Creative Commons Zero v1.0 Universal
8.11k stars 3k forks source link

Ch 16 - some further reading for ex65 and 66 #825

Open funct7 opened 1 year ago

funct7 commented 1 year ago

Ex 65 can be a little surprising if you have overloads of debug_rep for char * and const char * compiled together with the specializations: you can't get the specializations to be called to save your life.

Of course the book says as much:

Specializations instantiate a template; they do not overload it. As a result, specializations do not affect function matching.

However, it's already a big book (so much for a "primer" 🥲), and it's easy to just skim over this important detail. It could also be confusing as to which is the best way to provide functionality with so many different ways to do the same thing.

I found a great link that goes a little further into this issue, which happens to answer ex 66 somewhat: http://www.gotw.ca/publications/mill17.htm

Hope this helps others who are not sure about all this specialization chaos.