STL List iterator

M

maverick

Consider the following class
foo.h
---------------------------------------------------
#include <list.h>
using namespace std ;
template < class CFooTemp> class CFoo
{
CFoo();
~CFoo() ;


list<CFooTemp *> m_list ;

list<CFooTemp *> iterator :: iter ;
};


list<CFooTemp *> iterator :: iter ;
This line gives me a compiler error

error: expected `;' before "iter"


Any clues as to why this would happen ?

Now i change to primitive type such as int it compiles fine
 
P

Pete Becker

red said:
typename list<CFooTemp *>::iterator iter;

typename isn't needed here: CFooTemp is not a dependent name. In fact,
it used to be illegal, but that made writing code too hard (like the
rules for semicolons in Pascal).

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
 
R

red floyd

Pete said:
typename isn't needed here: CFooTemp is not a dependent name. In fact,
it used to be illegal, but that made writing code too hard (like the
rules for semicolons in Pascal).

OK, I'm thoroughly confused.

If I had list<CFooTemp>::iterator, would I have needed a typename? If
so, what's the difference between that and list<CFooTemp*>::iterator?
 
M

Michiel.Salters

Pete said:
typename isn't needed here: CFooTemp is not a dependent name.

'iterator' is. It depends on CFooTemp. The compiler doesn't know
iterator is a
type when it's compiling CFoo. It only knows this when CFoo is
instantiated
because it can then pick the correct list specialization. That's too
late.

Regards,
Michiel Salters
 
R

red floyd

'iterator' is. It depends on CFooTemp. The compiler doesn't know
iterator is a
type when it's compiling CFoo. It only knows this when CFoo is
instantiated
because it can then pick the correct list specialization. That's too
late.

Regards,
Michiel Salters

Thanks, Michiel. I thought I was going crazy.
 

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,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top