Skip to content

Instantly share code, notes, and snippets.

@yzchen
Created January 9, 2019 19:47
Show Gist options
  • Select an option

  • Save yzchen/17c072a3ed40a7923f0faf4c76a098ea to your computer and use it in GitHub Desktop.

Select an option

Save yzchen/17c072a3ed40a7923f0faf4c76a098ea to your computer and use it in GitHub Desktop.
A test about double free error, need a copy constructor
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
// This is a test about double free error
// You need to add a copy constructor for class Test
class Test{
int *myArray;
public:
Test() {
myArray = new int[10];
}
~Test() {
delete[] myArray;
}
// Test(const Test &other) {
// myArray = new int[10];
// memcpy(myArray, other.myArray, 10);
// }
};
int main(){
queue<Test> q;
Test t;
q.push(t); // error occurs here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment