Solved

Initializing Iterators

Posted on 2013-05-15
3
520 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adjust the position 3 75
designing in object programming 12 131
print bytes of an integer 6 48
MDT Create a bootable media for BIOS 2 25
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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.

738 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