I am trying to implement a std::map object with a structure that
contains a std::map object within each object (is that possible?). In
the class below I have a number of variables and functions that all seem
to work...except the std::map named "eyMap". The function "setYearMax"
fails when I execute the code, but other setters and getters work as
desired.
Is there something fundamentally wrong with this logic, or is here
another way to declare and use a map-like structure within this class?
Please advise. TIA
class DBE_Info
{
public:
void setYoB(int year);
void setAge(int age);
void setType(char eType);
void setYearMax(int eYear);
void setRefName(string name);
void updPart(void);
void normalizeAgeType(void);
void computeYoB(void);
int getYoB(void);
int getAge(void);
int getEYear(void);
string getRefName(void);
char getType(void);
int getPart(void);
int getYearMax(int eYear);
DBE_Info(); // This is the constructor
~DBE_Info(); // This is the destructor
private:
int dAge, eYear;
int birthYear;
int yearsPart;
char entType;
string refName;
map<int, int> eyMap;
map<int, int>::iterator eyIter;
};
// Member functions definitions including constructor
DBE_Info::DBE_Info(void)
{
birthYear = yearsPart = dAge = eYear = 0;
entType = 'A';
refName = "";
eyMap.clear(); // is this needed within the constructor?
}
DBE_Info::~DBE_Info(void) { return; }
void DBE_Info::setYoB(int year) { birthYear = year; return; }
void DBE_Info::setRefName(string name) { refName = name; return; }
string DBE_Info::getRefName(void) { return refName; }
int DBE_Info::getEYear(void) { return eYear; }
int DBE_Info::getYoB(void) { return birthYear; }
void DBE_Info::setType(char eType) { entType = (eType == ' ') ?
'A' : eType; return; }
char DBE_Info::getType(void) { return entType; }
void DBE_Info::updPart(void) { yearsPart++; return; }
int DBE_Info::getPart(void) { return yearsPart; }
void DBE_Info::computeYoB(void)
{
dAge = nAge, eYear = eventYear;
if(nAge >= maxAgegroup)
{
int qq = (cGender == 'M') ? 0 : 1;
entType = age2Str[cRCode-'a'][nAge][qq].cEntType;
return;
} // if
if(birthYear > 0) return;
int wYear = eventYear;
if((wYear >= 0) && (wYear < 100)) wYear +=1900;
if(wYear < EPOCH) wYear +=100;
birthYear = eventYear-nAge;
return;
} // computeYoB
void DBE_Info::setYearMax(int eYear)
{
eyMap[eYear] = maxAgegroup; // This FAILS!!
return;
} // setYearMax
int DBE_Info::getYearMax(int eYear)
{
eyIter = eyMap.find(eYear);
if(eyIter != eyMap.end()) return eyIter->second;
else
{
return 89;
}
} // getYearMax
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus