One question.
How do I make sure that an iterator to a vector is valid when reading from one.
eg
if(itBestRect is valid, ie is pointing to an element in the vector)
{
RECT recSrcHole;
recSrcHole.top=itBestRect->top;
recSrcHole.left=itBestRect->left;
recSrcHole.right=itBestRect->right;
recSrcHole.bottom=itBestRect->bottom;
}
Thanks
Vector Errors during compile in Visual Studio 2008
Quote:Original post by utilaeYou'll need to set it to an invalid value to start with. For example:
One question.
How do I make sure that an iterator to a vector is valid when reading from one.
eg
if(itBestRect is valid, ie is pointing to an element in the vector)
{
RECT recSrcHole;
recSrcHole.top=itBestRect->top;
recSrcHole.left=itBestRect->left;
recSrcHole.right=itBestRect->right;
recSrcHole.bottom=itBestRect->bottom;
}
Thanks
vector<RECT>::iterator itSearchRect=lstFilledRects.begin();vector<RECT>::iterator itBestRect=lstFilledRects.end(); // Set to invalid value hereint nSrcRectMaxBottom=0, nSrcRectMinLeft=recContainer.right;while(itSearchRect!=lstFilledRects.end()){ // Blah}if(itBestRect != lstFilledRects.end()){ // Iterator isn't pointing at the end of the vector, so it's valid.}
Don't bother fiddling around with iterators for a "high water-mark" algorithm. The standard library already implements that algorithm for you. The only iterators you need to worry about are the endpoints of the search region, and the result.
bool compareRects(const RECT& a, const RECT& b) { // return true if b is "better" than a, and false otherwise}vector<RECT>::iterator itBestRect = std::max_element(lstFilledRects.begin(), lstFilledRects.end(), compareRects);if (itBestRect == lstFilledRects.end()) { // The "best" rectangle could not be found; but the only way that can happen // is if lstFilledRects is empty.} else { // go ahead and do something with the "best" rectangle.}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement