c++ c++-faq copy-constructor assignment-operator rule-of-three
#include <queue>
using namespace std;
class Test{
int *myArray;
public:
Test(){
myArray = new int[10];
}
~Test(){
delete[] myArray;
}
};
int main(){
queue<Test> q
Test t;
q.push(t);
}
Run Code Online (Sandbox Code Playgroud)
运行此操作后,我收到运行时错误"double free or corruption".如果我摆脱析构函数内容(delete),它工作正常.怎么了?