468,457 Members | 1,598 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,457 developers. It's quick & easy.

STL List iterator

Consider the following class
foo.h
---------------------------------------------------
#include <list.h>
using namespace std ;
template < class CFooTempclass 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

Oct 23 '06 #1
7 5320
list<CFooTemp *iterator :: iter ;
This line gives me a compiler error

error: expected `;' before "iter"
How about
list<CFooTemp*>::iterator iter;

Michael

Oct 23 '06 #2
maverick wrote:
Consider the following class
foo.h
---------------------------------------------------
#include <list.h>
No such header.

#include <list>
using namespace std ;
template < class CFooTempclass CFoo
{
CFoo();
~CFoo() ;
list<CFooTemp *m_list ;

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

Oct 23 '06 #3
red floyd wrote:
>
#include <list>
>using namespace std ;
template < class CFooTempclass CFoo
{
CFoo();
~CFoo() ;
list<CFooTemp *m_list ;

list<CFooTemp *iterator :: iter ;
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.
Oct 24 '06 #4
Pete Becker wrote:
red floyd wrote:
>>
#include <list>
>>using namespace std ;
template < class CFooTempclass CFoo
{
CFoo();
~CFoo() ;
list<CFooTemp *m_list ;

list<CFooTemp *iterator :: iter ;
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).
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?
Oct 24 '06 #5
By adding the typename before the list my compilation error was
eliminated
red floyd wrote:
Pete Becker wrote:
red floyd wrote:
>
#include <list>

using namespace std ;
template < class CFooTempclass CFoo
{
CFoo();
~CFoo() ;
list<CFooTemp *m_list ;

list<CFooTemp *iterator :: iter ;
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).

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?
Oct 24 '06 #6
Pete Becker wrote:
red floyd wrote:

#include <list>
using namespace std ;
template < class CFooTempclass CFoo
{
CFoo();
~CFoo() ;
list<CFooTemp *m_list ;

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

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

Oct 25 '06 #7
Mi*************@tomtom.com wrote:
Pete Becker wrote:
>red floyd wrote:
>>#include <list>

using namespace std ;
template < class CFooTempclass CFoo
{
CFoo();
~CFoo() ;
list<CFooTemp *m_list ;

list<CFooTemp *iterator :: iter ;
typename list<CFooTemp *>::iterator iter;
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
Thanks, Michiel. I thought I was going crazy.
Oct 25 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by kazio | last post: by
12 posts views Thread by Brett L. Moore | last post: by
15 posts views Thread by jayesah | last post: by
6 posts views Thread by Henrik Goldman | last post: by
12 posts views Thread by Howard | last post: by
6 posts views Thread by APEJMAN | last post: by
1 post views Thread by subhajit12345 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.