Question on vector of vector iterators

D

David Crawford

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<IntVectorIteratorVector*,
std::vector<IntVectorIteratorVector,
std::allocator<IntVectorIteratorVector> > >' requested
 
M

Marcus Kwok

David Crawford said:
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;

?
 
D

David Crawford

Yep. Just been looking at it for too long I guess.

Now have it as
typedef IntVectorIteratorVector::iterator
IntVectorIteratorVectorIterator;
 
D

deane_gavin

David said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top