In my SDL program, I am using a map construct to simulate an "infinite" array of objects within a certain class. The code manages to compile fine, but when I run the program, as soon as one of the functions using the maps is trigger, the program crashes, returning a value of 3.
So, here s exactly what I m doing:
class MyClass
{
public:
int MyFunction();
protected:
std::map< int, MyObject > MyMap;
}
int MyClass::MyFunction()
{
...
int i;
if( MyMap.empty() )
{
i = 1;
}
else
{
i = MyMap.size() + 1;
}
MyMap[ i ] = PreviouslyDefinedObject;
return i;
}
When MyFunction() is called from a MyClass object, the crash occurs. It seems to happen whenever anything of use is done with MyMap: it crashes if you comment out the penultimate line and just try to return i, and it crashes if you just set i = 1 and then assign an object to MyMap[i]
This is the first time I ve ever used a map, so I m not certain I m using them right. Is this a basic mistake somewhere? Can anyone point me in the right direction? Cheers.