xlc - A template dependent name that is a type must be qualified with "typename"

Discussion in 'C++' started by pervinder, Mar 22, 2005.

  1. pervinder

    pervinder Guest

    Hi,
    I get an error on line #3 while compiling the program segment on aix
    (xlc - va6)
    While this warning is not seen with gcc

    "test.cpp" line 200.18: 1540-0152 (W) A template dependent name that
    is a type must be qualified with "typename".


    #1 template<class KeyType,
    class ValueType, ....>
    #2 class Iterator;
    #3 friend class Cpp_SortedList<KeyType,ValueType,.....> :: Iterator;

    Does anyone has a hint for this behaviour ?

    R/s
    pervinder
     
    pervinder, Mar 22, 2005
    #1
    1. Advertising

  2. Re: xlc - A template dependent name that is a type must be qualifiedwith "typename"

    pervinder schrieb:
    > Hi,
    > I get an error on line #3 while compiling the program segment on aix
    > (xlc - va6)
    > While this warning is not seen with gcc


    gcc has been warning about this since version 3.0. Anything before that
    is totally outdated (current version is 3.4.3 and 4.0 is due soon...)

    > "test.cpp" line 200.18: 1540-0152 (W) A template dependent name that
    > is a type must be qualified with "typename".
    >
    >
    > #1 template<class KeyType,
    > class ValueType, ....>
    > #2 class Iterator;
    > #3 friend class Cpp_SortedList<KeyType,ValueType,.....> :: Iterator;
    >
    > Does anyone has a hint for this behaviour ?


    As the warning says, types that depend on a template parameter must be
    qualified with the typename keyword:

    friend class typename Cpp_SortedList<KeyType,ValueType,.....> :: Iterator;

    This way, you tell the compiler that
    Cpp_SortedList<KeyType,ValueType,.....> :: Iterator is a type and not a
    data member or member function.

    template< typename T >
    struct Foo
    {
    std::vector< int >::iterator it1;
    // fine, std::vector< int > does not depend on T
    std::vector< T >::iterator it2;
    // error, std::vector< T > depends on T
    typename std::vector< T >::iterator it3;
    // fine, typename used
    };

    Cheers,
    Malte
     
    Malte Starostik, Mar 22, 2005
    #2
    1. Advertising

  3. pervinder

    Rolf Magnus Guest

    Malte Starostik wrote:

    > pervinder schrieb:
    >> Hi,
    >> I get an error on line #3 while compiling the program segment on aix
    >> (xlc - va6)
    >> While this warning is not seen with gcc

    >
    > gcc has been warning about this since version 3.0. Anything before that
    > is totally outdated (current version is 3.4.3 and 4.0 is due soon...)
    >
    >> "test.cpp" line 200.18: 1540-0152 (W) A template dependent name that
    >> is a type must be qualified with "typename".
    >>
    >>
    >> #1 template<class KeyType,
    >> class ValueType, ....>
    >> #2 class Iterator;
    >> #3 friend class Cpp_SortedList<KeyType,ValueType,.....> :: Iterator;
    >>
    >> Does anyone has a hint for this behaviour ?

    >
    > As the warning says, types that depend on a template parameter must be
    > qualified with the typename keyword:
    >
    > friend class typename Cpp_SortedList<KeyType,ValueType,.....> :: Iterator;


    ....although it looks strange in this particular place. I mean, you already
    said "class", so what could that class be, other than a type? I guess it's
    just needed here to make the rules simpler.
     
    Rolf Magnus, Mar 22, 2005
    #3
  4. pervinder

    pervinder Guest

    The typename did not work, compiler generates the same warnings again
    The Cpp_SortedList is defined as below :-

    template<class KeyType,
    class ValueType,
    class LessThan = less<KeyType>,
    class MemoryBase = Cpp_CachedSmallObject
    > class Cpp_SortedList : public MemoryBase

    {
    protected: ,,,
    ,,,,,,,,,,,,,,,,,
    }

    R/s
    pervinder

    Rolf Magnus <> wrote in message news:<d1p1lb$eso$04$-online.com>...
    > Malte Starostik wrote:
    >
    > > pervinder schrieb:
    > >> Hi,
    > >> I get an error on line #3 while compiling the program segment on aix
    > >> (xlc - va6)
    > >> While this warning is not seen with gcc

    > >
    > > gcc has been warning about this since version 3.0. Anything before that
    > > is totally outdated (current version is 3.4.3 and 4.0 is due soon...)
    > >
    > >> "test.cpp" line 200.18: 1540-0152 (W) A template dependent name that
    > >> is a type must be qualified with "typename".
    > >>
    > >>
    > >> #1 template<class KeyType,
    > >> class ValueType, ....>
    > >> #2 class Iterator;
    > >> #3 friend class Cpp_SortedList<KeyType,ValueType,.....> :: Iterator;
    > >>
    > >> Does anyone has a hint for this behaviour ?

    > >
    > > As the warning says, types that depend on a template parameter must be
    > > qualified with the typename keyword:
    > >
    > > friend class typename Cpp_SortedList<KeyType,ValueType,.....> :: Iterator;

    >
    > ...although it looks strange in this particular place. I mean, you already
    > said "class", so what could that class be, other than a type? I guess it's
    > just needed here to make the rules simpler.
     
    pervinder, Mar 29, 2005
    #4
  5. Re: xlc - A template dependent name that is a type must be qualifiedwith "typename"

    pervinder schrieb:
    > The typename did not work, compiler generates the same warnings again
    > The Cpp_SortedList is defined as below :-
    >
    > template<class KeyType,
    > class ValueType,
    > class LessThan = less<KeyType>,
    > class MemoryBase = Cpp_CachedSmallObject
    > > class Cpp_SortedList : public MemoryBase

    > {
    > protected: ,,,
    > ,,,,,,,,,,,,,,,,,
    > }
    >
    >>friend class typename Cpp_SortedList<KeyType,ValueType,.....> :: Iterator;


    Only now I see it's a friend declaration...how is Cpp_SortedList< ...
    >::Iterator declared? If it's a typedef you can't befriend it :-(

    Any chance you could provide a minimal but complete example that
    produces the problem?

    Cheers,
    Malte
     
    Malte Starostik, Mar 29, 2005
    #5
    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. Jakob Bieling

    Q: typename or not typename?

    Jakob Bieling, Mar 14, 2006, in forum: C++
    Replies:
    2
    Views:
    356
    Rolf Magnus
    Mar 14, 2006
  2. Sanil
    Replies:
    2
    Views:
    4,763
    James Kanze
    Dec 14, 2007
  3. Szabolcs Borsanyi

    Pointer to qualified poitner to qualified object

    Szabolcs Borsanyi, May 30, 2008, in forum: C Programming
    Replies:
    13
    Views:
    564
    Keith Thompson
    Jun 8, 2008
  4. puzzlecracker
    Replies:
    1
    Views:
    524
    James Kanze
    Aug 7, 2008
  5. Replies:
    3
    Views:
    274
    Zhihao Yuan
    Nov 20, 2012
Loading...

Share This Page