PDA

View Full Version : "Convert" iterator



jano_alex_es
12th May 2009, 15:38
Hi,

it is possible to check and transform an iterator to another type? doesn't seem so, but I wanted to be 100% sure.

In my case, I have a vector with objects and I'd like to transform the iterator to one of that object.

For instance:



CSQLGroups::VSQLGROUPS vGroups;

fillGroups(vGroups);
for(itGr = vGroups.begin(); itGr != vGroups.end(); itGr++)
{
QString name = itGt.sname;
QString surname = itGt.ssurname;

if anotherVector.contains(itGr) //But it's an iterator, it's different.
{}
}


thanks!

wysota
12th May 2009, 19:49
Try:

if(anotherVector.contains(*itGr))

jano_alex_es
13th May 2009, 09:19
It does when I try with vectors of integers, strings... but it doesn't, logically, when is a non standard type (it can't compare)

thanks!

lyuts
19th May 2009, 18:50
how do you declare your vector?

jano_alex_es
20th May 2009, 08:18
it's a group of structs, that's why it's not possible (if I don't reimplement the == operator)

lyuts
20th May 2009, 09:51
why do you need to reimplement ==? You are not using it in your code.

jano_alex_es
20th May 2009, 10:22
because in the error message said "can't compare " and the compiler stops in the line (not in my code, in the already-built classes) where the code tries to compare the iterator with the struct :P

lyuts
20th May 2009, 10:24
Yep, got it.