【发布时间】:2010-03-02 02:46:15
【问题描述】:
迭代有问题。我认为问题与 const 正确性有关。我假设 B::getGenerate() 应该是 const 代码才能正常工作,但我无法控制 B::getGenerate()。
非常感谢任何帮助。
提前致谢, jbu
代码如下:
int
A::getNumOptions() const
{
int running_total = 0;
BList::const_iterator iter = m_options.begin();
while(iter != m_options.end())
{
if(iter->getGenerate()) //this is the line of the error; getGenerate() returns bool; no const in signature
{
running_total++;
}
}
return running_total;
}
1>.\A.cpp(118) : 错误 C2662: 'B::getGenerate()' : 无法将 'this' 指针从 'const B' 转换为 'B &'
【问题讨论】:
-
我假设实际上你确实在 while 循环内的 if 语句之后推进了 iter。