August 2012
Intermediate to advanced
976 pages
30h 17m
English
For our next example, we’ll define an ordinary nontemplate version of debug_rep to print strings inside double quotes:
// print strings inside double quotesstring debug_rep(const string &s){ return '"' + s + '"';}
Now, when we call debug_rep on a string,
string s("hi");cout << debug_rep(s) << endl;
there are two equally good viable functions:
• debug_rep<string>(const string&), the first template with T bound to string
• debug_rep(const string&), the ordinary, nontemplate function
In this case, both functions have the same parameter list, so obviously, each function provides an equally good match for this call. However, the nontemplate version is selected. For the same reasons that the most specialized of ...
Read now
Unlock full access