I'm porting a project from VC7 to VC8 and thus run into problems with using const_iterators as pointers (allowed in VC7 but allowed in VC8)
For instance, I've got a std::list (accessed via a const_iterator) that contains a number of objects, Assume it's descriptions of different cars.
Now, I need to print/output all the cars that follow after one specific car in the list. To do this, I've got a function that finds a specific car in the list, and returns a reference to it. The calling function can then start outputting the remainder of the list.
I've got a CCarList class that contains the actual list, providing Begin() and End() methods that map to the normal begin() and end().
The TCarIterator is not (as of now) a class, but merely a typedef for a const_iterator of CCarList
The "find" function looks like this. It returns true/false if the searched car was found. If found, the FoundIt iterator input variable is set to the found car -- the calling function may the begin iterating through the rest of the list.
This works very well in VC7 but I suppose I get problems in VC8?
bool CMain::Find(CCarList *pList, TCarIterator &FoundIt, CString sName) {
bool bFound = false;
for (TCarIterator cit = pList->Begin(); !bFound && cit != pList->End(); cit++) {
if ((*cit)->Name() == sName) {
bFound = true;
FoundIt = cit;
}
}
return bFound;
}
1)
Can I do this in VC8? Is it possible to return a pointer to a "specific point" in the list, as identified by a const_iterator?
2)
Also, in other parts of the application, I compare a TCarIterator variable with another, to see if they point to the exakt same object in a list. I suppose that this is not possible in VC8 as well?
3)
Sometimes I set a TCarIterator variable to NULL, to indicate that it's not yet set to an object in a list (not "initiated")
I could check for "==end()" instead, but I suppose that this is linked to any potential problems with issue 1) above?
Any ideas on this?
Thanks
/Stefan Lennerbrant
Start Free Trial