Created
January 9, 2019 19:47
-
-
Save yzchen/17c072a3ed40a7923f0faf4c76a098ea to your computer and use it in GitHub Desktop.
A test about double free error, need a copy constructor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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