So i need to create an array of dynamic size containing pairs of objects and I have the following piece of code:
#include <utility>
#include <iostream>
#include <string>
using namespace std;
int main() {
cout << "Hey #1" << endl;
pair<string, int> *array;
array = new pair<string, int>[4];
cout << "Hey #2" << endl;
delete array;
cout << "Hey #3" << endl;
}
and the output I get is
Hey #1
Hey #2
Segmentation fault (core dumped)
which means that something goes wrong when the delete
operator gets called?
What am I missing here? Any help would be appreciated!