Hey folks, i have a problem with a vector im attempting to program. There are no compile errors but during run time i get an error saying:
"Debug Assertion Failed!
Program:...filepath\GA.exe
File:...include\vector
Line: 779
Expression: vector subscript out of range"
etc...
I have tried stepping throught the program to no avail, it seems to run fine for the time im stepping through. This leads me to beleive that somewhere, something is either running out of memory or looping too far and trying to access a part of the vector that dosnt exist. Although i cant find anywhere obvious within the program.
Im not using any complicated algorithms, just basic member functions for the vector, however the vector is a vector of a custom struct, so i was wondering if that could be the cause of the problem.
Iv attached the complete file with the header to this post for further inspection, but im pretty sure it dosnt get more complicated than the snippets below.
Here is the code for the struct and the types of member functions i have called:
struct Population
{
Population::Population(DNA* pChrome, int iFitness)
{m_iFitness = iFitness; m_pChrome = pChrome; m_iCumulativeFitness = 0;}
Population::~Population(){delete m_pChrome;};
DNA* m_pChrome;
int m_iFitness;
int m_iCumulativeFitness;
};
//vector member function example calls:
vector<Population*> m_vPopulation2; //Declaration
for(unsigned int i=0; i<m_iPopDensity; i++)
{
Population* pTemp = new Population(ConvertToBinary(m_iDensity[i]), m_iDensity[i]);
m_vPopulation2.push_back(pTemp);
}
//Example2
inline int GetVectorInt(int index){return m_vPopulation2[index]->m_iFitness;};
//Example 3
for(unsigned long int i=0; i<m_vPopulation2.size(); i++)
m_vPopulation2[i]->m_iFitness = m_iDensity[i];
//Example 4
for(unsigned long int i=0; i<m_vPopulation2.size(); i++)
m_vParentPop2[i] = m_vPopulation2[i]->m_pChrome->Breed(m_vParentPop2[i], m_fCrossoverChance, m_fMutateChance);
[ATTACH]17818[/ATTACH]
[ATTACH]17819[/ATTACH]
Any help muchly appreciated.