C26816返回shared_ptr.get()警告
C26816读:“指针指向分配在堆栈上的内存”
vs vs vs vs viss viss this shared_ptr.get()的警告,但是我的印象是,返回的指针指向堆上的托管对象,因此有效为有效只要引用了智能指针?
我还没有遇到任何问题,但是我想确认我是否应该注意此警告,或者是视觉工作室的另一个怪癖。
示例:
int* test()
{
auto a = std::make_shared<int>(5);
someVector.push_back(a);
return a.get(); // warning here
}
值得注意的是,当我对其进行测试时,它似乎不会发生在unique_ptr.get()上。
C26816 reads: "The pointer points to memory allocated on the stack"
VS gives this warning on returning of shared_ptr.get(), but I was under the impression that the returned pointer pointed to the managed object on the heap and thus is valid as long as the smart pointer is referenced?
I haven't yet encountered any issues with this yet, but I want to confirm whether or not I should heed this warning, or if it's another eccentricity of Visual Studio.
Example:
int* test()
{
auto a = std::make_shared<int>(5);
someVector.push_back(a);
return a.get(); // warning here
}
Notably it doesn't appear to happen on unique_ptr.get() when I tested it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论