<list> iterators with nested templates

This is a discussion on <list> iterators with nested templates within the C++ Programming forums, part of the General Programming Boards category; Having trouble declaring a class member which is an iterator. Problem seems to be something to do with nesting of ...

  1. #1
    external validation
    Join Date
    Dec 2004
    Posts
    9

    <list> iterators with nested templates

    Having trouble declaring a class member which is an iterator.
    Problem seems to be something to do with nesting of templatisation.
    Tried various experiments, and alot of googling, but to no avail.

    Here's the problem...

    Code:
      template <typename MyTypeOne>
      class MyInnerClass {
      public:
        MyTypeOne theData;
      };
    
      
      template <typename MyTypeTwo>
      class MyOuterClass {
      public:
    
      list < MyInnerClass<MyTypeTwo> > theListMember;
      // this line compiles ok
    
      list <int>::iterator theSimpleIterMember;
      // this line compiles ok
    
      list <MyInnerClass<MyTypeTwo> >::iterator theNestingIterMember;
      // this line causes the compiler to generate the following error...
      // error: expected `;' before "theNestingIterMember"
      // my compiler is g++
    Can anybody shed some light on this?

    Regards,
    Doug W

  2. #2
    C/C++Newbie Antigloss's Avatar
    Join Date
    May 2005
    Posts
    212
    it works fine under msvc++6

  3. #3
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    Code:
    //try this:
    template<class MyTypeOne>
    class Aclass
    {
    void foo();
    //code
    };
    template<class MyTypeOne>
    void Aclass::foo()
    {
    //code
    }

  4. #4
    external validation
    Join Date
    Dec 2004
    Posts
    9
    That only compiles as:

    Code:
    //try this:
    template<class MyTypeOne>
    class Aclass
    {
    void foo();
    //code
    };
    
    
    template<class MyTypeOne>
    void Aclass<MyTypeOne>::foo()
    // note addition of "<MyTypeOne>"
    {
    //code
    }
    But I'm not sure how that helps with the iterator-specific issue
    (excuse me if I've missed thepoint)

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    It should be:
    Code:
    typename list <MyInnerClass<MyTypeTwo> >::iterator theNestingIterMember;
    VC++ 7.1 requires typename also.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class templates and iterators
    By creativeinspira in forum C++ Programming
    Replies: 2
    Last Post: 06-30-2007, 03:35 PM
  2. Nested array vs. tree
    By KONI in forum Tech Board
    Replies: 1
    Last Post: 06-07-2007, 04:43 AM
  3. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 04:01 PM
  4. Questions about Templates
    By Shamino in forum C++ Programming
    Replies: 4
    Last Post: 12-17-2005, 11:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21