473,396 Members | 1,866 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,396 software developers and data experts.

Iterator not working with nested class template ?

Hi - I can't seem to figure this one out, help is appreciated:

Header file:
template <class T>
class Foo {
T val;
};

template<class T>
class Bar {
T bar_func();
list < Foo<T> > val_list;
};

No complaints from the compiler on the header file, but the following will not compile:

template <class T> T Bar<T>::bar_func() {
list < Foo<T> >:: iterator iter;
....
}

The compiler (gnu g++) complains about the "list < Foo<T> >::iterator iter" line - specifically saying it expects a semicolon before "iter".

Is it something with the nested template?
Thanks for any help !
Dec 7 '06 #1
4 2045
did you copy/pasted your code? Because you have an extra space:

Expand|Select|Wrap|Line Numbers
  1. template <class T> T Bar<T>::bar_func() {
  2. list < Foo<T> >:: iterator iter;
  3. ....             |
  4.                  |
  5.                 here
  6. }
Dec 7 '06 #2
DeMan
1,806 1GB
Removed, given what I just reread
Dec 7 '06 #3
Sorry - I typed it in to remove the extraneous info - there is no space in the actual code:

list < Foo<T> >::iterator iter;

Thanks.
Dec 7 '06 #4
Figured it out, it needed the "typename" keyword to disambiguate:


typename list < Foo<T> >::iterator iter;
Dec 7 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Scott Smedley | last post by:
Hi all, I'm trying to write a special adaptor iterator for my program. I have *almost* succeeded, though it fails under some circumstances. See the for-loop in main(). Any pointers/help...
6
by: Markus Dehmann | last post by:
I have a class Foo that contains a map<string,string> internally. Now, I want that users can iterate over the entries in the map. What's the best way to do that? I tried a method like...
13
by: Dan Tsafrir | last post by:
is the following code standard? (cleanly compiles under g++-4.0.2): struct Asc { bool operator()(int a, int b) {return a < b;} }; struct Des { bool operator()(int a, int b) {return b > a;} };...
3
by: chriscorbell | last post by:
I'm curious about what appears to be a restriction on using an STL container inside a user-defined template, esp. using an iterator to such a container. It's not clear to me if this is a general...
1
by: flopbucket | last post by:
Hi, For the learning experience, I am building a replacement for std::map. I built a templated red-black tree, etc., and all the basic stuff is working well. I implemented basic iterators and...
0
by: mailforpr | last post by:
Hi. Let me introduce an iterator to you, the so-called "Abstract Iterator" I developed the other day. I actually have no idea if there's another "Abstract Iterator" out there, as I have never...
21
by: T.A. | last post by:
I understand why it is not safe to inherit from STL containers, but I have found (in SGI STL documentation) that for example bidirectional_iterator class can be used to create your own iterator...
1
by: Axel Gallus | last post by:
I built a container (without a template), an iterator as a nested class and a "find"-method: iterator has a friend relationship with Hash_Map and vice versa. class Hash_Map { iterator...
3
by: pnayak | last post by:
Hi, I am trying to implement an iterator to a List class. The code is included below. I get the following compiler error. At the point where I use a class that is defined inside a template...
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: 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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.