小编tac*_*che的帖子

从函数返回的unique_ptr的范围是什么?

这会正常吗?(见例)

unique_ptr<A> source()
{
    return unique_ptr<A>(new A);
}


void doSomething(A &a)  
{  
    // ...
}  

void test()  
{  
    doSomething(*source().get());   // unsafe?
    // When does the returned unique_ptr go out of scope?
}
Run Code Online (Sandbox Code Playgroud)

c++ unique-ptr

8
推荐指数
2
解决办法
1722
查看次数

标签 统计

c++ ×1

unique-ptr ×1