Having problems iterating. Problem has to do with const correctness, I think. I assume B::getGenerate() should be const for this code to work, but I don’t have control over B::getGenerate().
Any help is greatly appreciated.
Thanks in advance,
jbu
Code follows:
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) : error C2662: ‘B::getGenerate()’ : cannot convert ‘this’ pointer from ‘const B’ to ‘B &’
Well, if
getGenerateis non-const, your iterator must be non-const. And if that’s the case, yourgetNumOptionswill also have to be non-const.If
getGenerateisn’t under you control, there isn’t anything else you can do. But if that method could beconst, bring it up with whoever implemented that method; tell them it should beconst.