ChenChen
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=CacheSiz e;};
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_pai r(k,&v));
}else{
m_map.erase(m_getlistpos(& (m_list.ba ck())));
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();!bfo und;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///////////////////// ////////// ////////// ///////
//////////////////////////
#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=CacheSiz
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_pai
}else{
m_map.erase(m_getlistpos(&
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();!bfo
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks very much for your comment.
My pleasure!
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;