且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

函数可以在return语句后继续吗?

更新时间:2023-11-13 15:21:28

否.但是,是的.return语句后将不执行该函数的任何行.但是,return语句也标记了函数的结尾,因此也标志了作用域的结尾.因此,如果您设法在堆栈上放置一个对象(例如局部变量),则会调用该析构函数.

No. But yes. No line of the function will be executed after the return statement. However, the return statement also marks the end of the function and therefor the end of the scope. So if you manage to have an object on the stack (like a local variable), it's destructor will be called.

但这不是您想要的.即使在return语句之后,您也不想释放返回的内容.

But that's not what you want. You don't want to free what you return, not even after the return statement.