Is it not possible to fill a map like this:
void Spel::Fill( void )
{
int buildslist[] = {3,3,2,2,2,2,3,2,2,2,2,3,3,2,2,2,2,1,1,1,1,1};
Building::buildings p;
for( int i = Building::INDIGOK; i < Building::STADSHUIS; i++)
{
p = (Building::buildings) i;
gebouwenMap[p] = buildslist[i];
}
}
This gives all 0. Building::buildings is an enum with some building names. The buildslist is a list of how many people could join that building.
First, there is not enough code to give an actual answer. Please improve your question so that we can help you properly.
Second, the title is misleading “Find function doesn’t return the right value”. There is no “find” function and there is no “return value” because the only function you show returns
void.Now thet this is sorted out, let me try to help you:
This is a cast from int to enum. I think this is bad C++ (probably undefined as in might work for some compiler but not as a rule of thumb). You would have to use a switch here I think.
Please write code in English. Do you imagine if someone you work with is Japanese and would write the code with japanese variable names? Even if the project is in Dutch, write code in English including comments.
EDIT: You might want to use strings instead of an enum here.
Try using a
std::map<std::string, int>to encode your building names instead of an enum, then use anstd::map::iteratorto iterate through it.