hmm... (iterator declaration problem)

This is a discussion on hmm... (iterator declaration problem) within the C++ Programming forums, part of the General Programming Boards category; I'm probably going to embarrass myself by asking this, as I'm expecting a complete oversight of something on my part, ...

  1. #1
    Registered User Stonehambey's Avatar
    Join Date
    Jan 2008
    Location
    Kent, UK
    Posts
    118

    hmm... (iterator declaration problem)

    I'm probably going to embarrass myself by asking this, as I'm expecting a complete oversight of something on my part, but I honestly can't see my error here.

    The following code

    Code:
    template<class T>
    bool Sequence<T>::isLinear(std::vector<T> v)
    {
        std::vector<T>::iterator i; //compiles fine without this line
    }
    generates the following error

    Code:
    sequence.cpp: In static member function ‘static bool Sequence<T>::isLinear(std::vector<T, std::allocator<_CharT> >)’:
    sequence.cpp:19: error: expected `;' before ‘i’
    I've only included the code in the function which gives the error, it compiles fine if I remove the declaration of the iterator.

    So what have I missed?

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Try this:

    Code:
    template<class T>
    bool Sequence<T>::isLinear(std::vector<T> v)
    {
        typename std::vector<T>::iterator i; //compiles fine with this line as well
    }
    That should fix it .

  3. #3
    Registered User Stonehambey's Avatar
    Join Date
    Jan 2008
    Location
    Kent, UK
    Posts
    118
    It compiles now, thanks. I'll go read up on the typename keyword as well.

    Cheers again

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 09:37 AM

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