Solved

Initializing Iterators

Posted on 2013-05-15
3
522 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 39169328
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 34

Assisted Solution

by:sarabande
sarabande earned 250 total points
ID: 39171193
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
ID: 39199212
Excellent information and this was a huge help - thank you!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

631 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