【发布时间】:2015-06-16 20:00:36
【问题描述】:
我有两个 C++ 对象。其中第一个包含第二个声明的向量:
std::vector<WormCell> cells; // The dynamic array of the worms cells
在第一个方法中,我尝试使用迭代器遍历向量并在第二个方法中调用方法,但出现错误。调用该方法的代码是:
void Worm::drawWorm(sf::RenderWindow &window)
{
for (std::vector<WormCell>::iterator it = cells.begin() ; it != cells.end(); ++it)
{
sf::Vector2f pos = it->getPosition;
circle.setPosition(pos);
}
}
错误是:
错误:绑定到函数的指针只能用于调用函数。
发生在 it->getPosition 上。
如何使用迭代器访问单元格中的方法?
【问题讨论】:
-
C++ 中的call 称为call,因为它包含函数call 运算符
()。it->getPosition行中的函数调用运算符在哪里???如果那里没有函数调用运算符,那你为什么称它为 call 呢?