#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main() {
vector<pair<int, int>*> *v;
pair<int, int> *x = new pair<int, int>();
cin >> x->first >> x->second;
v->push_back(x);
cout << v->size() << endl;
return 0;
}
Why does this code get run-time error? I dont understand. All I do is appending a pair pointer to a vector of pair pointer.
vis initialised, because it's a pointer the object isn't created implicitly.vector<pair<int, int>*> *v = new vector<pair<int, int>*>();should work. This would explain why you're getting a segfault - you're trying to access a null pointerv.