开发者

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_low开发者_开发技巧er_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 (i.e. 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:
    typename nested-name-specifier identifier
    typename nested-name-specifier templateopt 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜