template <class _Key, class _Tp, class _Compare=less<_Key> > class IsMap : public map<_Key, _Tp, _Compare> { public: _Tp& operator[](const _Key& __k) throw (ExptAppl) { for (IsMap<_Key, _Tp, _Compare>::iterator it = this->begin(); it != this->end(); it++) if ((*it).first == __k) return (*it).second; string errMsg = "Element <" + __k + "> does not exist"; throw ExptAppl("", 0, 3003, "", (char*)errMsg.c_str()); } };
Quote:What I understood? IsMap is a class template which inherits the class map. So here the generic Data type used here are: _key -> This Denotes Key. _Tp -> This Denotes Type. _Compare=less<_key> -> A comparison function. Now we need to understand how Map works? std::map <key_type,data_type,[comparison> The key comparison function, an ordering whose argument type is key_type; it returns true if its first argument is less than its second argument, and false otherwise. This is also defined as map::key_compare.This means that if you want to retrieve every key, value pair stored in the map, you can retrieve them in the order of the keys. What I did not? just the line : _Tp& operator[](const _Key& __k) throw (ExptAppl) The Rest I have guessed. Can you please help me understanding this whole piece of code by identifying this missing piece of logic? Thanks Deb
Quote:Found the solution here : http://www.cplusplus.com/reference/map/map/operator
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)