相关疑难解决方法(0)

为什么类的析构函数被调用两次?

抱歉,如果这个问题听起来很愚蠢,我就是在关注SO的专家并亲自尝试一些例子,这就是其中之一.我确实尝试了搜索选项,但没有找到这种答案.

class A
{
    public:
         A(){cout<<"A Contruction"<<endl;}
        ~A(){cout<<"A destruction"<<endl;}
};

int main()
{
    vector<A> t;
    t.push_back(A()); // After this line, when the scope of the object is lost.
}
Run Code Online (Sandbox Code Playgroud)

为什么类的析构函数被调用两次?

c++ destructor

24
推荐指数
2
解决办法
1万
查看次数

标签 统计

c++ ×1

destructor ×1