stl iterator problem

Started by
1 comment, last by Fruny 18 years, 1 month ago
Hi, I have a base class for my managers like this:

template <class tHandle,class tResource,class tFactoryHashType, class tHashType>
class cMgrHashed 
{
public:
    typedef typename std::hash_map<tHashType,tHandle>::iterator		cResIt;

    inline cResIt	getFirst		()      {return resMap.begin();}
    inline cResIt	getLast			()      {return resMap.end();}

    //...
private:
    typedef std::hash_map<tHashType,tHandle>	cResMap;
    cResMap		resMap;
}



Then i have a mgr for my vertexbuffers like this:

#include "GRaVertexBuffer.h"
class cVbMgr : public VA::HBRM::cMgrHashed<cVbHndl,aVertexBuffer,std::string,std::string>
{
public:
   void Foo();

};

void cVbMgr::Foo()
{
    for(cVbIt it = getFirst();it!=getLast();++it)
    {
	
    }
}



cVbIt is declared as following:

typedef  	VA::HBRM::cMgrHashed<cVbHndl,aVertexBuffer,std::string,std::string>::cResIt		cVbIt;

This gives me the following error on cVbIt in the for lus: p:\Programmatie\C++\MyLibs\Renderer\GRcVbMgr.cpp(160): error C2440: 'initializing' : cannot convert from 'VA::HBRM::cMgrHashed<tHandle,tResource,tFactoryHashType,tHashType>::cResIt' to 'std::list<_Ty,_Ax>::iterator' with [ tHandle=GR::cVbHndl, tResource=VA::HBRM::tResource, tFactoryHashType=VA::HBRM::tFactoryHashType, tHashType=VA::HBRM::tHashType ] and [ _Ty=stdext::_Hmap_traits<std::string,GR::cVbHndl,stdext::hash_compare<std::string,std::less<std::string>>,std::allocator<std::pair<const std::string,GR::cVbHndl>>,false>::value_type, _Ax=stdext::_Hmap_traits<std::string,GR::cVbHndl,stdext::hash_compare<std::string,std::less<std::string>>,std::allocator<std::pair<const std::string,GR::cVbHndl>>,false>::allocator_type ] Why does he want to convert my hashmap iterator to a list iterator??? greets
Advertisement
Quote:Original post by codehunter13
Why does he want to convert my hashmap iterator to a list iterator???


Is it possible that there is another symbol with the same name as your iterator type declared in another namespace?

You should be careful when mixing namespaces. There are all sorts of rules dealing with resolving namespaces (google for 'Koenig lookup').

It can be enlightening to see how the standard library implements things.

Stephen M. Webb
Professional Free Software Developer

I assume that would be because the hash_map class internally uses a std::list to store the elements (it makes sense if you think about it for a minute, you would use the list anyway for collision resolution), only using hashing to find out where in the list you need to go (i.e. it hashes into an array of list iterators). Using a single list rather than an array of lists allows for easier traveral.

I would investigate the iterator's template parameters rather than the iterator's container type. Though to be honest, I don't see a mismatch. Unless your Foo() member function happens to be const.

See if you can find out what hash_map::iterator really is a typedef for to.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement