Question on Lists and Classes.

V

virenpratapsingh

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.
 
V

Victor Bazarov

virenpratapsingh said:
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
 
R

Rolf Magnus

virenpratapsingh said:
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.
 
D

Daniel T.

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/>
 

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

Forum statistics

Threads
473,767
Messages
2,569,573
Members
45,046
Latest member
Gavizuho

Latest Threads

Top