[英]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
实际上,每个
typedef
声明后跟typename
都会出现此错误
I have compiled this code succesfully in the past using VS2005 and VS2008 on XP. 我在过去使用VS2005和VS2008在XP上成功编译了这段代码。
I am currently building on Ubuntu 9.10, using gcc 4.4.1 我目前正在使用gcc 4.4.1在Ubuntu 9.10上构建
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. 我在Google上查看了这个错误,看起来行上没有必要输入
typename
(发生错误的地方),因为标准假设是该位置的标识符是一种类型。 g++ seems to be complaining because it expects any typename
declaration there to be qualified (ie A::B). g ++似乎在抱怨,因为它希望那里的任何
typename
声明都是合格的(即A :: B)。
Is this is a correct diagnosis of the problem - if so, then how do I "fully qualify" the typename
? 这是对问题的正确诊断 - 如果是,那么我如何“完全限定”
typename
?
In short, how may I resolve this problem? 简而言之,我该如何解决这个问题?
typename
is needed to specify that a dependent name is in fact a type. 需要
typename
来指定依赖名称实际上是一种类型。 Your names are not dependent names, so no typename
is required or allowed. 您的名称不是依赖名称,因此不需要或不允许使用
typename
。
Update The standard actually has this syntax definition: 更新标准实际上有这个语法定义:
typename-specifier :typename-speci fi er :
typename nested-name-specifier identifier
typename nested-name-speci fi er标识符
typename nested-name-specifier
template opt simple-template-id
typename nested-name-speci fi er
template 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). 您可以使用typename关键字的其他两个位置在模板参数列表和
using
声明中(在后一种情况下,它也必须后跟一个嵌套的名称说明符)。
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. 在类/函数定义之前,您最多只能有一个
template<>
规范。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.