简体   繁体   中英

expected nested-name-specifier before 'sktraits'

This is a snippet of a class template which is causing compilation errors:

/* Secondary index class */
template<class TKey, class TVal, class key_traits, class val_traits>
template<class TSecKey, class sktraits> 
class CBtreeDb<TKey, TVal, key_traits, val_traits>::CDbSecondaryIndex: protected CBtreeDb<TKey, TVal>, public IDeallocateKey
{
public:
 typedef TSecKey           skey_type;
 typedef typename sktraits                         skey_traits;
 typedef CNewDbt<TSecKey, sktraits>                CDbSKey;
 typedef typename iterator_t<TSecKey, skey_traits> iterator;
 typedef typename iter_lower_bound_t<skey_type>    iter_lower_bound;
 typedef typename iter_upper_bound_t<skey_type>    iter_upper_bound;

 CDbSecondaryIndex(CDbEnv* pEnv, u_int32_t flags, bool bAllowDuplicates=false):
  CBtreeDb(pEnv, flags, bAllowDuplicates)
 {

 }

    // Class implementation continues ...
};

The compiler error message I get is:

expected nested-name-specifier before 'sktraits'.

Actually, this error occurs on every typedef declaration followed by typename

I have compiled this code succesfully in the past using VS2005 and VS2008 on XP.

I am currently building on Ubuntu 9.10, using gcc 4.4.1

I looked this error up on Google and it appears that the typename isn't necessary on the line (where the error occurs), because the standard assumption is that an identifier in that position is a type. g++ seems to be complaining because it expects any typename declaration there to be qualified (ie A::B).

Is this is a correct diagnosis of the problem - if so, then how do I "fully qualify" the typename ?

In short, how may I resolve this problem?

typename is needed to specify that a dependent name is in fact a type. Your names are not dependent names, so no typename is required or allowed.

Update The standard actually has this syntax definition:

typename-specifier :
nested-name-specifier identifier nested-name-speci fi er标识符
nested-name-specifier opt simple-template-id nested-name-speci fi er opt simple-template-id

The two other places you can use the typename keyword are in the template parameter list and in the using declaration (in the latter case it too must be followed by a nested name specifier).

The following is not allowed:

template<class A>
template<class B> class F { ... };

You can have at most one template<> specification before a class/function definition.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM