Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

expected nested-name-specifier before 'sktraits'

Tags:

c++

traits

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 (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?

like image 802
Stick it to THE MAN Avatar asked Feb 17 '10 12:02

Stick it to THE MAN


2 Answers

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 templateoptsimple-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).

like image 142
n. 1.8e9-where's-my-share m. Avatar answered Oct 12 '22 18:10

n. 1.8e9-where's-my-share m.


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.

like image 37
dirkgently Avatar answered Oct 12 '22 18:10

dirkgently