473,382 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 5753
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: kazio | last post by:
Hello, So, I need to have double linked, circular list (last element point to the first one and first one points to the last one). I thought maybe I could use list container from STL, but...
12
by: Brett L. Moore | last post by:
Hi, I have had trouble determining whether the STL list.size() operation is O(1) or O(n). I know the list is a doubly-linked list, so if the size() operation begins at the head, then counts to...
4
by: Vince | last post by:
Hi, I am not used to template and I cannot find what's wrong with this code : Compiler(MSVS 7) complains at line : class iterator : public std::iterator<... Here is the source code
6
by: PengYu.UT | last post by:
Hi, Suppose I have a list which contains pointers. I want the pointer got by dereferencing the iterator be a pointer pointing to a const object. But std::list<const T*>::const_iterator doens't...
3
by: janzon | last post by:
Hi! Sorry for the bad subject line... Here's what I mean. Suppose we deal with C++ standard integers lists (the type is indifferent). We have a function f, declared as list<intf(int); Now...
15
by: jayesah | last post by:
Hi All, List and its iterator work as following way : list<intmylist; list<int>::iterator itr; itr = mylist.begin(); cout << (*itr); But I want something like this:
6
by: Henrik Goldman | last post by:
Hello, I have a dataset which consist of a string username and string hostname as a key and then an integer representing a count as the matching "second" value in a pair. So far I've used...
12
by: Howard | last post by:
Is there an easy way to get an iterator (*not* a reverse-iterator) to the last element in a list? The last() function returns the element itself, not an iterator. Thanks, -Howard
1
by: David Bilsby | last post by:
All Apologies for cross posing this but I am not sure if this is a VC 8 STL bug or simply an invalid use of the iterator. I have a PCI card access class which basically abstracts a third party...
6
by: APEJMAN | last post by:
I know what I'm posting here is wired, but it's been 3 days I'm workin g on these codes, but I have no result I post the code here I dont wanne bother you, but if any one of you have time to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.