Solved

Initializing Iterators

Posted on 2013-05-15
3
516 Views
Last Modified: 2013-05-27
I have a piece of code converting from Microsoft Visual Studio 6 to 2008. When I compile the following under VS 2008:

	

// Declare the iterators that will hold the earliest requests and subrequests
// and initialize them to NULL
std::set<ShrPtr<Requests> >::const_iterator FirstRequest;
std::set<ShrPtr<SubRequests> >::const_iterator FirstSubRequest;
FirstRequest = NULL;
FirstSubRequest = NULL;

Open in new window


I get the following compiler error --


Requests.cpp(443) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion)
        c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xtree(419): could be 'std::_Tree<_Traits>::const_iterator &std::_Tree<_Traits>::const_iterator::operator =(const std::_Tree<_Traits>::const_iterator &)'
        with
        [
            _Traits=std::_Tset_traits<ShrPtr<Request>,std::less<ShrPtr<Request>>,std::allocator<ShrPtr<Request>>,false>
        ]
        while trying to match the argument list '(std::_Tree<_Traits>::const_iterator, int)'
        with
        [
            _Traits=std::_Tset_traits<ShrPtr<Request>,std::less<ShrPtr<Request>>,std::allocator<ShrPtr<Request>>,false>
        ]

I actually agree with the compiler and I am surprised this compiled at all under Visual Studio 6. The question then becomes how to do this.
0
Comment
Question by:volleyballjerry
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
Comment Utility
VC6 is from a time where there was no standardization of C++, that followed later. So the implementation of the designed C++ features was not "standard" thus the above might have worked these days. In a nutshell, if you remove the lines

FirstRequest = NULL;
FirstSubRequest = NULL;

Open in new window


and replace them e.g. with

FirstRequest = Requests.begin();
FirstSubRequest = SubRequests.begin();

Open in new window


you should be fine. Alonve the removal of the 'NULL' assignments should do it.
0
 
LVL 32

Assisted Solution

by:sarabande
sarabande earned 250 total points
Comment Utility
vc6 used simple pointers for most iterators of the stl. that's why you could assign a NULL.

with visual studio all these simple iterators have been implemented by class objects derived from iterator baseclass. those iterators don't support an initialization with NULL.

note, that doesn't mean that you can't use pointers where an iterator was required. for example, the following code will compile at older or newer systems:

int arr[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
if (std::find(&arr[0], &arr[10], 7) != &arr[10])
    ...

Open in new window


here, pointers to a c array were used instead of iterators.

Sara
0
 

Author Closing Comment

by:volleyballjerry
Comment Utility
Excellent information and this was a huge help - thank you!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now