抱歉,如果这个问题听起来很愚蠢,我就是在关注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)
为什么类的析构函数被调用两次?