简体   繁体   English

作为类成员的shared_ptr破坏堆栈?

[英]shared_ptr as class member corrupts stack?

I have a shared_ptr in the class like this 我在这样的课程中有一个shared_ptr

class App
{
public:
    App(){};
    ~App(){};

private:

    boost::shared_ptr<int> ab;
};

when I instanciate one App class in main, the stack gets corrupted? 当我实例化main中的一个App类时,堆栈损坏了吗?

int main(){
   App myApp;
}

Does any one know why the error :" Run-Time Check Failure #2 - Stack around the variable 'myApp' was corrupted." 是否有人知道错误的原因:“运行时检查失败2-变量'myApp'周围的堆栈已损坏”。 appears, in Visual Studio? 在Visual Studio中出现?

shared_ptr needs no initialization it will be zero anyway or not? shared_ptr不需要初始化,还是会为零? This is quite strange 这很奇怪

您粘贴的代码很好,shared_ptr有一个明智的默认ctor并会破坏它

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

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