Compiler error dependent name is not a type prefix with 'typename' toindicate a type

S

Sanil

Hi Friends,
I'm getting a compile error on vs2005 that I dont understand. The
help
explains that this is a breaking change for VC++.NET 2005 compiler,
made in
order to conform to the ISO C++ standard, and I've tried it using evc+
+ 4.0 sp4 and
it compiles ok.

Code is as follows.............

//paramstring.h

template <class T> class ParameterStringAW
{
public:
typedef T* PT;
typedef const T* PCT;

class CKeyValuePair
{

protected:
TString m_strKey;
TString m_strValue;
BOOL m_bIgnoreCase;

public:
CKeyValuePair(PCT szKey, PCT szValue, BOOL bIgnoreCase) :
m_strKey(szKey), m_strValue(szValue),m_bIgnoreCase(bIgnoreCase)
{
}
~CKeyValuePair()
{
}
PCT GetValue() const
{
return m_strValue.c_str();
}
void SetValue( PCT szValue )
{
m_strValue = szValue;
}
PCT GetKey() const
{
return m_strKey.c_str();
}
BOOL Is( PCT szKeyToCompare) const
{
if (NULL == szKeyToCompare)
return FALSE;

if (m_bIgnoreCase)
return (0 == CompareNoCase(m_strKey, TString(szKeyToCompare)));
else
return ( m_strKey == szKeyToCompare );
}
};

typedef CKeyValuePair* PKeyValuePair;
typedef std::vector< PKeyValuePair > KeyValueList;


};

/
***********************************************************************************************/
paramstring.cpp


template <class T>
ParameterStringAW<T>::pKeyValuePair ParameterStringAW<T>::Exists( PCT
szKey ) const // this is the line where i get errors...
{


}

warning C4346: 'ParameterStringAW<T>::pKeyValuePair' : dependent name
is not a type
prefix with 'typename' to indicate a type

error C2143: syntax error : missing ';' before
'ParameterStringAW<T>::Exists'

error C1903: unable to recover from previous error(s); stopping
compilation NMUTF8.cpp

Any insight would be appreciated.
 
M

Michael DOUBEZ

Sanil a écrit :
Hi Friends,
I'm getting a compile error on vs2005 that I dont understand. The
help
explains that this is a breaking change for VC++.NET 2005 compiler,
made in
order to conform to the ISO C++ standard, and I've tried it using evc+
+ 4.0 sp4 and
it compiles ok.

Code is as follows.............

//paramstring.h

template <class T> class ParameterStringAW
{
public:
typedef T* PT;
typedef const T* PCT; [snip]

template <class T>
ParameterStringAW<T>::pKeyValuePair ParameterStringAW<T>::Exists( PCT
szKey ) const // this is the line where i get errors...
{


} [snip]
Any insight would be appreciated.

This should be:
template <class T>
ParameterStringAW<T>::pKeyValuePair ParameterStringAW<T>::Exists(
ParameterStringAW<T>::pCT szKey ) const

Michael
 
J

James Kanze

Sanil a écrit :
I'm getting a compile error on vs2005 that I dont
understand. The help explains that this is a breaking
change for VC++.NET 2005 compiler, made in order to conform
to the ISO C++ standard, and I've tried it using evc+ + 4.0
sp4 and it compiles ok.
Code is as follows.............
//paramstring.h
template <class T> class ParameterStringAW
{
public:
typedef T* PT;
typedef const T* PCT; [snip]
template <class T>
ParameterStringAW<T>::pKeyValuePair ParameterStringAW<T>::Exists( PCT
szKey ) const // this is the line where i get errors...
{
} [snip]
Any insight would be appreciated.
This should be:
template <class T>
ParameterStringAW<T>::pKeyValuePair ParameterStringAW<T>::Exists(
ParameterStringAW<T>::pCT szKey ) const

You mean

template <class T>
typename ParameterStringAW<T>::pKeyValuePair
ParameterStringAW<T>::Exists( PCT szKey ) const

The typename on the return value is necessary; if not, the
compiler assumes that it is *not* a type, which causes no end of
errors afterwards. And he doesn't need any qualifiers on the
parameter---parameters for a member function are looked up in
class scope. (And he doesn't need the typename, because PCT is
local to the template, and known to be a type, even before the
template is instantiated.)
 

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,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top