Parameterized Template Parameters

Discussion in 'C++' started by Aaron Carroll, Dec 9, 2005.

  1. Consider the following:

    #include <map>

    template <class T>
    void f()
    {
    typedef std::map<T, int> Mymap;
    Mymap::iterator iter;
    }

    Compiling with both GCC and Comeau gives an error along the lines of
    `expected a ";" before "iter".' The same code with the map parameter
    T replaced with a concrete type compiles just fine. Instantiating a
    "Mymap" seems to work.

    Why can I create a "Mymap" object, but not a "Mymap::iterator" object?

    Cheers,
    -- Aaron
     
    Aaron Carroll, Dec 9, 2005
    #1
    1. Advertising

  2. Aaron Carroll wrote:
    > Consider the following:
    >
    > #include <map>
    >
    > template <class T>
    > void f()
    > {
    > typedef std::map<T, int> Mymap;
    > Mymap::iterator iter;


    typename Mymap::iterator iter;
     
    Neelesh Bodas, Dec 9, 2005
    #2
    1. Advertising

  3. Aaron Carroll

    Earl Purple Guest

    Neelesh Bodas wrote:
    > Aaron Carroll wrote:
    > > Consider the following:
    > >
    > > #include <map>
    > >
    > > template <class T>
    > > void f()
    > > {
    > > typedef std::map<T, int> Mymap;
    > > Mymap::iterator iter;

    >
    > typename Mymap::iterator iter;


    The compilers are correct to reject the code but it would be nice if
    they could identify the error and give an appropriate message.
    (Something compiler vendors could work on perhaps?)
     
    Earl Purple, Dec 9, 2005
    #3
    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. ian
    Replies:
    5
    Views:
    569
  2. Sebastian Faust
    Replies:
    4
    Views:
    433
    Sebastian Faust
    Oct 18, 2003
  3. christopher diggins
    Replies:
    16
    Views:
    785
    Pete Becker
    May 4, 2005
  4. Lambda
    Replies:
    0
    Views:
    534
    Lambda
    Apr 27, 2008
  5. kito
    Replies:
    2
    Views:
    439
Loading...

Share This Page