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

P

pervinder

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
 
M

Malte Starostik

pervinder said:
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
 
R

Rolf Magnus

Malte said:
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...)


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.
 
P

pervinder

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 said:
class Cpp_SortedList : public MemoryBase
{
protected: ,,,
,,,,,,,,,,,,,,,,,
}

R/s
pervinder
 
M

Malte Starostik

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

template<class KeyType,
class ValueType,

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

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top