Sign in to follow this  
codehunter13

stl iterator problem

Recommended Posts

codehunter13    122
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

Share this post


Link to post
Share on other sites
Bregma    9214
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.

Share this post


Link to post
Share on other sites
Fruny    1658
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this