【发布时间】:2010-06-28 11:39:33
【问题描述】:
我目前正在尝试打印我正在开发的游戏中玩家的运动历史。在每一轮结束时,每个玩家都在正或负方向移动了一些量,这被记录为移动向量中的 int。最终,我想绘制每个玩家的移动方向与时间的关系,但我无法从二维向量中提取数据。
所以我尝试的第一件事就是迭代并打印所有元素,但这并不能编译:
void output_movement(const std::vector< std::vector<int> > & movement){
std::vector< std::vector<int> >::iterator row;
std::vector<int>::iterator col;
for (row = movement.begin(); row != movement.end(); ++row) {
for (col = row->begin(); col != row->end(); ++col) {
std::cout << **col;
}
}
}
编译器给出了这个我不太明白的错误信息:
hg_competition.cpp:45: error: no match for ‘operator=’ in ‘row = ((const std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >*)money_movement)->std::vector<_Tp, _Alloc>::begin [with _Tp = std::vector<int, std::allocator<int> >, _Alloc = std::allocator<std::vector<int, std::allocator<int> > >]()’
/usr/include/c++/4.4/bits/stl_iterator.h:669: note: candidates are: __gnu_cxx::__normal_iterator<std::vector<int, std::allocator<int> >*, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > >& __gnu_cxx::__normal_iterator<std::vector<int, std::allocator<int> >*, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > >::operator=(const __gnu_cxx::__normal_iterator<std::vector<int, std::allocator<int> >*, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > >&)
非常感谢任何帮助!
【问题讨论】: