I have a problem when I try to use a struct in my program. The program returns Segmentation Fault even now when I just declare a vector of it.
What I have is a class and in the header file i declare my struct among other things (dont know where else to put it)
1 2 3 4 5 6 7
struct data
{
string name;
int score;
};
vector<data> mHighscoreData;
This is the only place where I use my struct, just declaring a vector of my struct (in the header aswell) and my program returns segmentation fault. When I comment out //vector<data> mHighscoreData , the segmentation fault dissapper. Does anyone know what I'm doing wrong?
just declaring a vector of my struct (in the header aswell)
To have global variables declared in headers, you should use extern and define them in a cpp file
Header: extern vector<data> mHighscoreData;
Cpp: vector<data> mHighscoreData;
This avoids multiple definitions of the same symbol
I said you should use extern for global variables, not for class members. Remove it and the declaration in the constructor
Your problem is somewhere else
Does the segmentation fault occur when that object gets constructed or when you are accessing some methods?
Are you initializing mHighscoreData in the constructor or using it in some function?