Ok, I'm thinking about the following C++ code:
foo (std::string str) {
// do whatever
}
foo(const char *c_str) {
foo(std::string(c_str));
}
I look at this code and think it needs to be rewritten to pass by reference. Basically, my fear is that the constructor will get called twice, once in the const char * version of foo and once again when the argument is passed to foo as a std::string, since it is set to pass by copy. My question is: am I right, or is g++ smart enough to take the constructor in the c string version and call it good? It seems like g++ wouldn't be able to do that but I'm just hoping someone who really knows can clarify it.