I cannot seem to access the map in the parent class from the child class, as I try to output the contents of the map and nothing is displayed.
BELOW I HAVE ADDED IN FUL CODE, CPRALLIF POP IULATE THE MAP IN THE transLate Mask () it will subsequentlyprint out the content,然而,如果在人口结构中填满地图,就会一字不出,我不知道为什么?
这里是我的法典。
//HEADER FILE
//////PARENT CLASS
#include <iostream>
#include <string>
struct TTYElementBase
{
//some code here
};
class element
{
public:
std::map<char,std::string> transMask;
std::map<char,std::string>::iterator it;
void populate();
};
//////CHILD CLASS .HPP
class elementV : public element
{
public :
std::string s1;
std::string s2;
elementV();
friend ostream &operator<< (ostream &, const elementV &);
void transLateMask();
};
//CPP FILE #include "example.h"
elementV::elementV()
{
}
void element::populate()
{
transMask[ D ]= D ; //WILL PRINT OUT NOTHING IF I POPULATE HERE
}
void elementV::transLateMask()
{
for ( it=transMask.begin() ; it != transMask.end(); it++ )
std::cout << (*it).first << std::endl;
}
int main()
{
element e;
e.populate();
elementV v;
v.transLateMask();
}
它没有产生任何结果——为什么?