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

时间:2011-04-04 09:59:31

标签: c++ boost shared-ptr

我在这个类中有一个shared_ptr

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

private:

    boost::shared_ptr<int> ab;
};

当我在main中实例化一个App类时,堆栈被破坏了?

int main(){
   App myApp;
}

有没有人知道错误的原因:“运行时检查失败#2 - 变量'myApp'周围的堆栈已损坏。”在Visual Studio中出现?

shared_ptr不需要初始化它无论如何都会为零? 这很奇怪

1 个答案:

答案 0 :(得分:4)

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

相关问题