简体   繁体   English

C++ 内存泄漏对象按函数返回

[英]C++ memory leak object return by function

Are there any memory leak?有没有内存泄漏? Does the object will be delete automaticly?对象会被自动删除吗?

int main ()
{
    SomeClass *someObj;
    ...
    someObj = &foo();
    ...
    return 0;
}

SomeClass foo()
{   
    ...
    return SomeClass();
}

There are no leaks because the code is invalid and shouldn't even compile.没有泄漏,因为代码无效,甚至不应该编译。 You can't take the address of a temporary ( &foo() ).您不能获取临时地址( &foo() )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM