Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Initializing Iterators

Posted on 2013-05-15
3
Medium Priority
?
524 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 1000 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 35

Assisted Solution

by:sarabande
sarabande earned 1000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

688 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