我认为我的问题与模板相关,但我只是不知道。我收到如下错误:
error: conversion from '__gnu_cxx::__normal_iterator > >'到非标量类型 '__gnu_cxx::__normal_iterator*, std::vector , std::allocator > > >'请求
和
'itera1 != ((FxPairRegistry*)this)->FxPairRegistry::mRegistryList。 std::vector<_Tp, _Alloc>::end [with _Tp = FxStreamable* (**)(), _Alloc = std::allocator]()" <="" code="">
在看起来像这样的代码中,
for (iter itera1 = mRegistryList.begin(); itera1 != mRegistryList.end(); itera1++)
{
if ((*itera1).first == id)
{
return (*itera1).second;
}
}
任何人都可以阐明出了什么问题吗?
更新:mRegistryList 定义为 vector; mRegistryList;
更新:itera 定义 typedef typename std::vector; >::iterator iter;
更新 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;
}
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::allocator<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;
}
发布评论
评论(1)
您的迭代器类型与
mRegistryList
vector
的迭代器类型不匹配。迭代器:std::vector >::iterator
容器:
std::vector
编辑:响应更新:
使用
vector ::iterator
- 不是其他不相关的迭代器。为了迭代
vector
容器,您需要一个vector::iterator
而不是vector::iterator
code>编辑:响应新更新:
由于此代码位于模板中,编译器不知道
std::vector::iterator
是一种类型 - 您必须通过添加前缀typename
告诉它将其视为类型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 avector<X>::iterator
not avector<SomethingElse>::iterator
EDIT: In response to new update:
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 prefixingtypename