Question on vector of vector iterators

Discussion in 'C++' started by David Crawford, Dec 15, 2005.

  1. 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
    -----------------------------------
    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?
     
    David Crawford, Dec 15, 2005
    #1
    1. Advertising

  2. David Crawford

    Marcus Kwok Guest

    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;


    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<IntVectorIteratorVector*,
    > 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
     
    Marcus Kwok, Dec 15, 2005
    #2
    1. Advertising

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

    Now have it as
    typedef IntVectorIteratorVector::iterator
    IntVectorIteratorVectorIterator;
     
    David Crawford, Dec 15, 2005
    #3
  4. David Crawford

    Guest

    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<IntVectorIteratorVector*,
    > 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, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim West
    Replies:
    14
    Views:
    6,236
    Alex Vinokur
    Dec 18, 2003
  2. Marcin Kaliciñski

    Iterators and reverse iterators

    Marcin Kaliciñski, May 8, 2005, in forum: C++
    Replies:
    1
    Views:
    489
    Kai-Uwe Bux
    May 8, 2005
  3. Replies:
    8
    Views:
    1,930
    Csaba
    Feb 18, 2006
  4. , India
    Replies:
    1
    Views:
    305
    joseph cook
    Aug 19, 2008
  5. , India
    Replies:
    10
    Views:
    1,084
    James Kanze
    Aug 8, 2009
Loading...

Share This Page