By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,918 Members | 2,240 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,918 IT Pros & Developers. It's quick & easy.

Question on vector of vector iterators

P: n/a
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?

Dec 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
David Crawford <cr************@gmail.com> 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
Dec 15 '05 #2

P: n/a
Yep. Just been looking at it for too long I guess.

Now have it as
typedef IntVectorIteratorVector::iterator
IntVectorIteratorVectorIterator;

Dec 15 '05 #3

P: n/a

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?


Dec 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.