BlueGhost79
Programmer
Hi,
I declare a std::map in my header file, but when I go to add an item to it in the class it crashes as it is null.
header file
class x
{
public:
void DoStuff();
private:
std::map<int, int> sample_data;
};
source file
void DoStuff()
{
//crashes here as sample_data is null
sample_data[4] = 5;
}
why would the sample_data variable be null?
void DoStuff()
{
//crashes here as sample_data is null
std::map<int, int> sample_data;
sample_data[4] = 5;
}
will work, if sample_data is a local variable.
I declare a std::map in my header file, but when I go to add an item to it in the class it crashes as it is null.
header file
class x
{
public:
void DoStuff();
private:
std::map<int, int> sample_data;
};
source file
void DoStuff()
{
//crashes here as sample_data is null
sample_data[4] = 5;
}
why would the sample_data variable be null?
void DoStuff()
{
//crashes here as sample_data is null
std::map<int, int> sample_data;
sample_data[4] = 5;
}
will work, if sample_data is a local variable.