Link to home
Start Free TrialLog in
Avatar of ChenChen
ChenChenFlag for Afghanistan

asked on

STL: <list> and <map>

Would anyone know what the problem is with the following code? I am getting a compiling error C2535: 'const float *__thiscall std::allocator<float const >::address(const float &) const' : member function already defined or declared

/////////////////////////////////////////////////////
#include <list>
#include <map>
#include <string>

using namespace std;

typedef int                         Key;
typedef float                    VALUE;

typedef list<const VALUE>                    MYLIST;
typedef map<const Key,const VALUE*>          MYMAP;
typedef MYLIST::iterator                    POSL;
typedef MYMAP::iterator                         POSM;


class VCache{
     
public:
     VCache(int CacheSize){m_size=CacheSize;};

     inline void insert(const Key& k,const VALUE& v){
          if(m_list.size()<m_size){
               m_list.push_front(v);
               m_map.insert(std::make_pair(k,&v));
          }else{
               m_map.erase(m_getlistpos(&(m_list.back())));
               m_list.pop_back();
          }
     }

         

private:
     MYLIST               m_list;
     MYMAP               m_map;
     POSL               posl;
     POSM               posm;
     
     int                    m_size;

     inline POSM m_getlistpos(const VALUE* v){
          bool bfound=false;

          POSM pos;
          for(pos=m_map.begin();!bfound;pos++)
               bfound=(pos->second==vp);
         
          return pos;
     }

};

void main(void){
     VCache vc(10);
     Key k=1;
     VALUE v=0.25;
     vc.insert(k,v);
}
//End////////////////////////////////////////////////
ASKER CERTIFIED SOLUTION
Avatar of LoungeLizard
LoungeLizard

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vbk_bgm
vbk_bgm

You can define the collections without the const qualifier
typedef list<VALUE>                    MYLIST;
typedef map<Key,VALUE*>          MYMAP;
If you need const collections then,
const MYLIST list1;
const MYMAP map1;

For simple traversal you can use const iterator
MYLIST::const_iterator myit;
Avatar of ChenChen

ASKER

Thanks very much for your comment.
My pleasure!