Cannot make const_iterator of templatized hash_map

Discussion in 'C++' started by Joseph Turian, Aug 2, 2005.

  1. In a class templatized by class T, I have the following two lines:

    hash_map<string, T> foo;
    hash_map<string, T>::const_iterator p;

    The first line compiles just fine.
    The second line gives the following error: "syntax error before `;'
    token"

    Any idea how to resolve this error?

    Thanks,
    Joseph
     
    Joseph Turian, Aug 2, 2005
    #1
    1. Advertising

  2. Joseph Turian wrote:
    > In a class templatized by class T, I have the following two lines:
    >
    > hash_map<string, T> foo;
    > hash_map<string, T>::const_iterator p;
    >
    > The first line compiles just fine.
    > The second line gives the following error: "syntax error before `;'
    > token"
    >
    > Any idea how to resolve this error?


    For dependent names, if they are types, add 'typename' to help your
    compiler:

    typename hash_map<string, T>::const_iterator p;

    More about it in the FAQ.

    V
     
    Victor Bazarov, Aug 2, 2005
    #2
    1. Advertising

  3. Okay, I figured it out:
    typename hash_map<string, T>::const_iterator p;

    However, I have no idea why this works.

    Joseph
     
    Joseph Turian, Aug 2, 2005
    #3
  4. Joseph Turian wrote:
    > Okay, I figured it out:
    > typename hash_map<string, T>::const_iterator p;
    >
    > However, I have no idea why this works.


    Read the FAQ.
     
    Victor Bazarov, Aug 2, 2005
    #4
  5. Victor Bazarov wrote:
    > Joseph Turian wrote:
    > > Okay, I figured it out:
    > > typename hash_map<string, T>::const_iterator p;
    > >
    > > However, I have no idea why this works.

    >
    > Read the FAQ.


    Victor,

    Which question should I be looking for?
    I searched the FAQ for typename, however I couldn't find the
    appropriate question.

    Thanks,

    Joseph
     
    Joseph Turian, Aug 2, 2005
    #5
  6. Joseph Turian wrote:
    > Victor Bazarov wrote:
    >
    >>Joseph Turian wrote:
    >>
    >>>Okay, I figured it out:
    >>> typename hash_map<string, T>::const_iterator p;
    >>>
    >>>However, I have no idea why this works.

    >>
    >>Read the FAQ.

    >
    >
    > Victor,
    >
    > Which question should I be looking for?
    > I searched the FAQ for typename, however I couldn't find the
    > appropriate question.


    I think section 35 should be of some assistance. Also, read the
    archives about "dependent name" or "dependent type".

    V
     
    Victor Bazarov, Aug 2, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. skscpp

    templatized state model

    skscpp, Sep 8, 2003, in forum: C++
    Replies:
    1
    Views:
    307
    Kasper van den Berg
    Sep 8, 2003
  2. hall
    Replies:
    2
    Views:
    311
  3. Paul Escherton

    Templatized operator () overload

    Paul Escherton, Nov 10, 2003, in forum: C++
    Replies:
    2
    Views:
    391
    tom_usenet
    Nov 10, 2003
  4. mrstephengross
    Replies:
    5
    Views:
    624
    Larry I Smith
    May 18, 2005
  5. xz
    Replies:
    21
    Views:
    1,147
    James Kanze
    Aug 6, 2007
Loading...

Share This Page