|
|
|
|
|
by cousin_it
3426 days ago
|
|
Your code is not the same as my code and you're probably new to C++. I suggest trying two changes: 1) Replace max("a", "b") with max("b", "a"). Run it, look closely at the result, and be enlightened. 2) Replace max("a", "b") with max<string>("a", "b"). Run it, look at the result, and be enlightened in a different way. As a small hint, your code invokes unspecified behavior, while my code invokes undefined behavior. If this exercise doesn't put the fear of C++ into you, then I don't know what will :-) |
|
EDIT: Not sure if this is it, but after some digging I've found [0] on lifetimes of temporaries. As for the lacking template argument, presumably const char* is inferred and a temporary string is constructed in main?
[0] http://stackoverflow.com/a/2784304