2 is wrong, while 1 and 3 are not so right

blaise (blaise)
syntaxly , 2 is wrong, because it try to return memory on the stack, when v() is finished the the memory on stack is released. the returned pointer ref to invalid memory.
1 and 3 are exactly the same except in debug build 1 will alloc one pointer on stack, in optimized mode, these 2 function will all probably return a constant address,semanticly, 1&3 are all wrong. The string "result of function v()" is allocated by compiler in Initialized data segement, but, notice, logically, it should be constant,although u can modify it.
const char^ v()
return "result of function v()";
will be the best way

2001-5-15 -04:00

回到话题: which one is right?

回到论坛: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论