P
Phlip
Bryan said:std::string foo()
{
char buf[16];
strcpy(buf, "this is a test.");
return std::string(buf);
}
it appears to me that foo should return garbage. however, "this is a test"
is printed correctly.
what am i missing here?
Google for "copy constructor". Then run that code thru the debugger and
trace inside the return statement to see one in action.
(Introductory C texts warn if you return buf, a character array, you get
undefined behavior; that's probably what you accidentally expected here.)