开发者

C++ Template Help

开发者 https://www.devze.com 2023-02-27 01:42 出处:网络
I think my issues are Template related but I just dont know. I am geting errors like: error: conversion from \'__gnu_cxx::__normal_iterator<FxStreamable* (***)(), std::vector<FxStreamable* (**)

I think my issues are Template related but I just dont know. I am geting errors like:

error: conversion from '__gnu_cxx::__normal_iterator<FxStreamable* (***)(), std::vector<FxStreamable* (**)(), std::a开发者_如何学Gollocator<FxStreamable* (**)()> > >' to non-scalar type '__gnu_cxx::__normal_iterator<std::pair<FxClassID, FxStreamable* (*)()>*, std::vector<std::pair<FxClassID, FxStreamable* (*)()>, std::allocator<std::pair<FxClassID, FxStreamable* (*)()> > > >' requested

and

no match for 'operator!=' in 'itera1 != ((FxPairRegistry<FxClassID, FxStreamable* (*)()>*)this)->FxPairRegistry<FxClassID, FxStreamable* (*)()>::mRegistryList. std::vector<_Tp, _Alloc>::end [with _Tp = FxStreamable* (**)(), _Alloc = std::allocator<FxStreamable* (**)()>]()'

in code that looks like

for (iter itera1 = mRegistryList.begin(); itera1 != mRegistryList.end(); itera1++)
{
    if ((*itera1).first == id)
    {
        return (*itera1).second;
    }
}

Can anyone shed some light on what is going wrong?

UPDATE: mRegistryList is defined vector<registeredObject *> mRegistryList;

UPDATE: itera is define typedef typename std::vector<pair<identifier,registeredObject> >::iterator iter;

UPDATE 3:

template <class identifier,class registeredObject> registeredObject     FxPairRegistry<identifier,registeredObject>::GetEntry(identifier id, FxBool assertValue)
{
for (std::vector<registeredObject *>::iterator itera1 = mRegistryList.begin(); itera1 != mRegistryList.end(); itera1++)
{
    if ((*itera1).first == id)
    {
        return (*itera1).second;
    }
}

if (assertValue)
    ASSERT_MSG(0,"Entry not found in the registry");
return NULL;
}


Your iterator type doesn't match the mRegistryList vector's iterator type.

iterator: std::vector<std::pair<FxClassID, FxStreamable* (*)()> >::iterator

container: std::vector<FxStreamable* (**)()>

EDIT: In response to update:

Use vector<registeredObject *>::iterator - not your other unrelated iterator.

In order to iterate over a vector<X> container, you need a vector<X>::iterator not a vector<SomethingElse>::iterator

EDIT: In response to new update:

for (typename std::vector<registeredObject *>::iterator itera1 = mRegistryList.begin(); itera1 != mRegistryList.end(); itera1++)
     ^^^^^^^^

Since this code is in a template, the compiler doesn't know that std::vector<registeredObject *>::iterator is a type - you have to tell it to treat it as a type by prefixing typename

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号