这是导致编译错误的类模板的片段:
/* 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 ...
};
我得到的编译器错误消息是:
expected nested-name-specifier before 'sktraits'.
实际上,这个错误发生在每个typedef
声明后面typename
我过去在 XP 上使用 VS2005 和 VS2008 成功编译了此代码。
我目前正在使用 gcc 4.4.1 在 Ubuntu 9.10 上构建
我在谷歌上查看了这个错误,似乎typename
不需要在线(发生错误的地方),因为标准假设是该位置的标识符是一种类型。g++ 似乎在抱怨,因为它希望typename
那里的任何声明都是合格的(即 A::B)。
这是对问题的正确诊断吗?如果是,那我该如何“完全符合”typename
呢?
简而言之,我该如何解决这个问题?