lundi 17 juillet 2017

Null pointer error in vector declaration

Im trying to declare a vector of vectors with predefined sizes. When I use the variables n and m to set the sizes, I get a null pointer error, but when I use fixed values, the code runs ok. I have not idead of what is causing it.

int n = a.size(); //a is a 771 characters string
int m = b.size(); //b is a 495 characters string
//Until here is fine, n and m have the correct values

//vector<vector<int> > dp(1001,vector<int>(1001,0)); //THIS WORKS FINE
vector<vector<int> > dp(n+1,vector<int>(m+1,0)); //THIS CAUSE NULL POINTER ERROR

Im using g++ with std=c++11 inside the QT Creator IDE.

Aucun commentaire:

Enregistrer un commentaire