【发布时间】:2010-06-14 23:40:43
【问题描述】:
我有一个这样声明的类:
class Level
{
private:
std::vector<mapObject::MapObject> features;
(...)
};
在它的一个成员函数中,我尝试像这样遍历该向量:
vector<mapObject::MapObject::iterator it;
for(it=features.begin(); it<features.end(); it++)
{
/* loop code */
}
这对我来说似乎很简单,但是 g++ 给了我这个错误:
src/Level.cpp:402: error: no match for ‘operator=’ in ‘it = ((const yarl::level::Level*)this)->yarl::level::Level::features.std::vector<_Tp, _Alloc>::begin [with _Tp = yarl::mapObject::MapObject, _Alloc = std::allocator<yarl::mapObject::MapObject>]()’
/usr/include/c++/4.4/bits/stl_iterator.h:669: note: candidates are: __gnu_cxx::__normal_iterator<yarl::mapObject::MapObject*,std::vector > >& __gnu_cxx::__normal_iterator<yarl::mapObject::MapObject*,std::vector > >::operator=(const __gnu_cxx::__normal_iterator<yarl::mapObject::MapObject*, ``std::vector<yarl::mapObject::MapObject, std::allocator<yarl::mapObject::MapObject> > >&)
有人知道为什么会这样吗?
【问题讨论】:
-
你的意思是
vector<mapObject::MapObject>::iterator it;?你在这里错过了一个尖括号。 -
C++ 的错误信息看起来像是呕吐物与更多的呕吐物混合在一起,并整齐地放在尖括号内。
-
@Aviral:我不经常使用 g++,但其他编译器(即使用 EDG 前端的 Visual C++ 和 Intel C++)有模板错误消息much 比这更容易阅读,IMO。