Oct 11, 2011 at 8:35am UTC
Hi, I am using C++ to model traffic simulation on Linux platform. I am trying to read data from map object and assigning data..attached is the relevant code
typedef std::vector<double> vDouble;
typedef std::map<int,vDouble> mpInt2Double;
std::map<std::string*, mpInt2Double> mpCache;
for(map<int, string>::iterator pTables = m_pCoordinator->m_LOStime2name.begin();
pTables != m_pCoordinator->m_LOStime2name.end();
pTables++)
// for each los table ....
{
string strTable;
if(mpCache[strTable] == NULL)
{
mpCache[strTable] = new mpInt2Double;
}
}
It gives compilation error as
no match for ‘operator[]’ in ‘((CZoneCache*)this)->CZoneCache::mpCache[strTable]’
Can anyone help me out?
Thanks in advance
Oct 11, 2011 at 9:34am UTC
std::map<std::string*, mpInt2Double> mpCache;
mpCache[strTable] == new mpInt2Double;
let me tell you the truth:
1. the key of mpCache you defined is string pointer type, but your input is string type.
2. the value of mpCache you defined is mpInt2Double type, but your assignment is it's pointer type.
you got that?
Oct 11, 2011 at 1:46pm UTC
when i removed the pointed part..it gave a an error like
error: no match for ‘operator==’ in ‘((CZoneCache*)this)->CZoneCache::mpCache.std::map<_Key, _Tp, _Compare, _Alloc>::operator[] [with _Key = std::basic_string<char>, _Tp = std::map<int, std::vector<double> >, _Compare = std::less<std::basic_string<char> >, _Alloc = std::allocator<std::pair<const std::basic_string<char>, std::map<int, std::vector<double> > > >, mapped_type = std::map<int, std::vector<double> >, key_type = std::basic_string<char>](((const std::map<std::basic_string<char>, std::map<int, std::vector<double> > >::key_type&)((const std::map<std::basic_string<char>, std::map<int, std::vector<double> > >::key_type*)(& strTable)))) == 0l’