Question on Lists and Classes.

Discussion in 'C++' started by virenpratapsingh, Jul 23, 2004.

  1. All,

    I would appreciate if someone can help me with this. Never used STL
    containers extensively, but facing this issue now.

    I have a Class A, which has a bunch of member variables and functios.

    I have a Class B, which has its own memmber variables, one of them
    being a

    list <Class A> a;

    so if I need to access the List through the member functions of Class
    B, like say while using an Iterator...do I need to overlad the
    iterator? Since the list isnt standard data-types, is there a need to
    overload the iterator ? I didnt think so, but I am getting some errors
    while compiling, when I

    list<A>::iterator iter(a);

    for( iter = iter.begin(), !iter, iter++
    {
    }

    The error(s) being C2264 and c2039(BEGIN NOT MEMBER OF ITERATOR)

    Because in the same problem I have used the iterator on a list of
    integers and obviously no problem there.

    Thanks.
     
    virenpratapsingh, Jul 23, 2004
    #1
    1. Advertising

  2. virenpratapsingh wrote:
    > All,
    >
    > I would appreciate if someone can help me with this. Never used STL
    > containers extensively, but facing this issue now.
    > [...]


    The problems you're having is due to your poor knowledge of how
    to use the containers. It is easily cured by a good book. Please
    find one and read it.

    A quick hint: iterators iterate, they don't begin, the containers
    begin and end. To get the beginning of a container call 'begin'
    for that container, not for the iterator.

    V
     
    Victor Bazarov, Jul 23, 2004
    #2
    1. Advertising

  3. virenpratapsingh

    Rolf Magnus Guest

    virenpratapsingh wrote:

    > All,
    >
    > I would appreciate if someone can help me with this. Never used STL
    > containers extensively, but facing this issue now.
    >
    > I have a Class A, which has a bunch of member variables and functios.
    >
    > I have a Class B, which has its own memmber variables, one of them
    > being a
    >
    > list <Class A> a;
    >
    > so if I need to access the List through the member functions of Class
    > B, like say while using an Iterator...do I need to overlad the
    > iterator? Since the list isnt standard data-types, is there a need to
    > overload the iterator ? I didnt think so, but I am getting some errors
    > while compiling, when I
    >
    > list<A>::iterator iter(a);
    >
    > for( iter = iter.begin(), !iter, iter++
    > {
    > }


    Ths small piece of code has about half a dozen errors. It's not
    surprising that it doesn't work. If that's not the actual code you
    tried, then show the actual code. A small, but complete C++ program
    that shows the problem you observed.

    > The error(s) being C2264 and c2039(BEGIN NOT MEMBER OF ITERATOR)


    There is neither something with the name ITERATOR, nor BEGIN. Maybe this
    isn't the original error message and you actually meant iterator and
    begin? In this case, the compiler is right. Iterators don't have a
    member begin(). The containers have one, though.

    > Because in the same problem I have used the iterator on a list of
    > integers and obviously no problem there.


    I guess you have used it differently then.
     
    Rolf Magnus, Jul 23, 2004
    #3
  4. virenpratapsingh

    Daniel T. Guest

    (virenpratapsingh) wrote:

    > I would appreciate if someone can help me with this.


    [snip]

    > so if I need to access the List through the member functions of Class
    > B, like say while using an Iterator...do I need to overlad the
    > iterator?


    No.

    > Since the list isnt standard data-types, is there a need to
    > overload the iterator ?


    No.

    > list<A>::iterator iter(a);
    >
    > for( iter = iter.begin(), !iter, iter++
    > {
    > }
    >
    > The error(s) being C2264 and c2039(BEGIN NOT MEMBER OF ITERATOR)
    >
    > Because in the same problem I have used the iterator on a list of
    > integers and obviously no problem there.


    Could you show us the code where you iterate over a list of integers
    please? Maybe there is a difference between them...

    You might also want to read:
    <http://www.sgi.com/tech/stl/>
     
    Daniel T., Jul 24, 2004
    #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. =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==

    List of lists of lists of lists...

    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==, May 8, 2006, in forum: Python
    Replies:
    5
    Views:
    442
    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==
    May 15, 2006
  2. Daniel Nogradi
    Replies:
    3
    Views:
    370
    Dennis Lee Bieber
    Nov 10, 2006
  3. Gabriel Zachmann

    Bug with lists of pairs of lists and append()

    Gabriel Zachmann, Sep 28, 2007, in forum: Python
    Replies:
    2
    Views:
    245
    Gabriel Zachmann
    Oct 1, 2007
  4. Gabriel Zachmann

    Bug with lists of pairs of lists and append()

    Gabriel Zachmann, Sep 28, 2007, in forum: Python
    Replies:
    5
    Views:
    280
    Gabriel Zachmann
    Oct 1, 2007
  5. antar2
    Replies:
    2
    Views:
    409
    Bighead
    Jul 17, 2008
Loading...

Share This Page