Iterator not working with nested class template ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bigbarn
    New Member
    • Dec 2006
    • 3

    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_fun c() {
    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 !
  • ivotron
    New Member
    • Dec 2006
    • 6

    #2
    did you copy/pasted your code? Because you have an extra space:

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

    Comment

    • DeMan
      Top Contributor
      • Nov 2006
      • 1799

      #3
      Removed, given what I just reread

      Comment

      • bigbarn
        New Member
        • Dec 2006
        • 3

        #4
        Sorry - I typed it in to remove the extraneous info - there is no space in the actual code:

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

        Thanks.

        Comment

        • bigbarn
          New Member
          • Dec 2006
          • 3

          #5
          Figured it out, it needed the "typename" keyword to disambiguate:


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

          Comment

          Working...