Missing Declarations Can Cause the Program to Misbehave
It is worth noting that for the char*
versions of debug_rep
to work correctly, a declaration for debug_rep(const string&)
must be in scope when these functions are defined. If not, the wrong version of debug_rep
will be called:
template <typename T> string debug_rep(const T &t);template <typename T> string debug_rep(T *p);// the following declaration must be in scope// for the definition of debug_rep(char*) to do the right thingstring debug_rep(const string &);string debug_rep(char *p){ // if the declaration for the version that takes a const string& is not in scope // the return will call debug_rep(const T&) with T instantiated to string return debug_rep(string(p));}
Ordinarily, ...
Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.