jeudi 19 mars 2015

NullReferenceException on push_back


I am getting a nullReferenceException when using vector.push_back on a new object.


In the code segment you see I have the vector object as a pointer but I originally had it as a non-pointer, I changed it in my troubleshooting out of desperation.


I stepped through the instantiation of BasicSolver completely to make sure the were no issues in it and also separated the instantiation from the push_back to help show that push_back is where the problem is occurring.


InformedSolver1&2 are children of BasicSolver. vector is included in BasicSolver and therefore in puzzleSolver also.



#include "stdafx.h"
#include "puzzleSolver.h"


PuzzleSolver::PuzzleSolver()
{
solvers = new vector<BasicSolver*>();
}

void PuzzleSolver::createPuzzle(string input)
{ //hitting step-over
BasicSolver* temp = new BasicSolver(input);// no errors
solvers->push_back(temp); // nullReferenceException
solvers->push_back(new InformedSolver1(input));
solvers->push_back(new InformedSolver2(input));
}


That should be all the relevant information. Let me know if you have any ideas as to what is causing this/ how to fix it! Thanks.




Aucun commentaire:

Enregistrer un commentaire