Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Question on vector of vector iterators

Reply
Thread Tools

Question on vector of vector iterators

 
 
David Crawford
Guest
Posts: n/a
 
      12-15-2005
I am trying to iterate through a vector of vector iterators and it's
failing at compile time on gcc 3.4.3. As far as I can tell it's
correct -- but the compiler isn't liking it obviously.

Here's a set of test statements that I tested it against besides my
original vector< myobj >:
-------------------------------------------------
typedef vector<int> IntVector;
typedef vector<int>::iterator IntVectorIterator;
typedef vector<IntVectorIterator> IntVectorIteratorVector;
typedef vector<IntVectorIteratorVector>::iterator
IntVectorIteratorVectorIterator;

IntVectorIteratorVector iviv;
IntVectorIteratorVectorIterator iviv_iter = iviv.begin();
-------------------------------------------------

The compiler gave:
-----------------------------------
error: conversion from
`__gnu_cxx::__normal_iterator<IntVectorIterator*,
std::vector<IntVectorIterator, std::allocator<IntVectorIterator> > >'
to non-scalar type
`__gnu_cxx::__normal_iterator<IntVectorIteratorVec tor*,
std::vector<IntVectorIteratorVector,
std::allocator<IntVectorIteratorVector> > >' requested
-----------------------------------
on the line that had the begin().

It looks like it's trying to set the iterator to one level deeper. Is
there a way for this to work?

 
Reply With Quote
 
 
 
 
Marcus Kwok
Guest
Posts: n/a
 
      12-15-2005
David Crawford <(E-Mail Removed)> wrote:
> I am trying to iterate through a vector of vector iterators and it's
> failing at compile time on gcc 3.4.3. As far as I can tell it's
> correct -- but the compiler isn't liking it obviously.
>
> Here's a set of test statements that I tested it against besides my
> original vector< myobj >:
> -------------------------------------------------
> typedef vector<int> IntVector;
> typedef vector<int>::iterator IntVectorIterator;
> typedef vector<IntVectorIterator> IntVectorIteratorVector;
> typedef vector<IntVectorIteratorVector>::iterator
> IntVectorIteratorVectorIterator;


Did you mean

typedef vector<IntVectorIterator>::iterator
IntVectorIteratorVectorIterator;

?

>
> IntVectorIteratorVector iviv;
> IntVectorIteratorVectorIterator iviv_iter = iviv.begin();
> -------------------------------------------------
>
> The compiler gave:
> -----------------------------------
> error: conversion from
> `__gnu_cxx::__normal_iterator<IntVectorIterator*,
> std::vector<IntVectorIterator, std::allocator<IntVectorIterator> > >'
> to non-scalar type
> `__gnu_cxx::__normal_iterator<IntVectorIteratorVec tor*,
> std::vector<IntVectorIteratorVector,
> std::allocator<IntVectorIteratorVector> > >' requested
> -----------------------------------
> on the line that had the begin().
>
> It looks like it's trying to set the iterator to one level deeper. Is
> there a way for this to work?


--
Marcus Kwok
 
Reply With Quote
 
 
 
 
David Crawford
Guest
Posts: n/a
 
      12-15-2005
Yep. Just been looking at it for too long I guess.

Now have it as
typedef IntVectorIteratorVector::iterator
IntVectorIteratorVectorIterator;

 
Reply With Quote
 
deane_gavin@hotmail.com
Guest
Posts: n/a
 
      12-16-2005

David Crawford wrote:

> I am trying to iterate through a vector of vector iterators and it's
> failing at compile time on gcc 3.4.3. As far as I can tell it's
> correct -- but the compiler isn't liking it obviously.
>
> Here's a set of test statements that I tested it against besides my
> original vector< myobj >:
> -------------------------------------------------
> typedef vector<int> IntVector;
> typedef vector<int>::iterator IntVectorIterator;
> typedef vector<IntVectorIterator> IntVectorIteratorVector;
> typedef vector<IntVectorIteratorVector>::iterator
> IntVectorIteratorVectorIterator;


You seem to be typedef'ing for the sake of typedef'ing here. Similar in
concept to

const int one_hundred = 100; // Look, ma! No magic numbers in my code.

typedef std::vector<grocery> ShoppingList has the potential to clarify
your code.

typedef vector<int> IntVector just rearranges the characters a bit and,
as you saw, leaves you just as confused.

Gavin Deane



>
> IntVectorIteratorVector iviv;
> IntVectorIteratorVectorIterator iviv_iter = iviv.begin();
> -------------------------------------------------
>
> The compiler gave:
> -----------------------------------
> error: conversion from
> `__gnu_cxx::__normal_iterator<IntVectorIterator*,
> std::vector<IntVectorIterator, std::allocator<IntVectorIterator> > >'
> to non-scalar type
> `__gnu_cxx::__normal_iterator<IntVectorIteratorVec tor*,
> std::vector<IntVectorIteratorVector,
> std::allocator<IntVectorIteratorVector> > >' requested
> -----------------------------------
> on the line that had the begin().
>
> It looks like it's trying to set the iterator to one level deeper. Is
> there a way for this to work?


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
plain iterators and reverse iterators on vector subramanian100in@yahoo.com, India C++ 10 08-08-2009 08:28 AM
question on invalidation of iterators on vector<T> subramanian100in@yahoo.com, India C++ 1 08-19-2008 09:35 AM
Free memory allocate by a STL vector, vector of vector, map of vector Allerdyce.John@gmail.com C++ 8 02-18-2006 12:48 AM
Iterators and reverse iterators Marcin Kaliciński C++ 1 05-08-2005 09:58 AM
Efficiency of map and vector iterators Jim West C++ 14 12-18-2003 07:53 PM



Advertisments