类型名C ++错误
|
很抱歉,这个标题含糊不清,很难描述。
我遇到的错误是这个,我不知道这意味着什么:
carray.h:176:错误:'类型名Carray :: is_iterator'名称'template template 结构Carray :: is_iterator',这不是一种类型
我有这个代码片段来检测某个东西是否是一个迭代器,并使用正确的重载(http://stackoverflow.com/questions/6050441/why-does-this-constructor-overload-resolve-incorrect)。这样编译:
template<class T> class Carray {
private:
// uses SFINAE to determine if the passed in type is indeed an iterator
template<class It>
class is_iterator_impl {
private:
typedef char yes[1];
typedef char no[2];
template<class C>
static yes& _test(typename C::iterator_category*);
template<class>
static no& _test(...);
public:
static const bool value = sizeof(_test<It>(0)) == sizeof(yes);
};
template<class It, bool check = is_iterator_impl<It>::value> struct is_iterator { typedef void type; };
template<class It> struct is_iterator<It*, false> { typedef void type; };
template<class It> struct is_iterator<It, false> { };
public:
template<class It>
Carray(It first, It last, typename is_iterator<It>::type *dummy = 0) {
// create array from 2 iterators
}
};
现在,我想将实现与声明分开,然后尝试了此操作,但出现了错误:
template<class T> class Carray {
private:
// uses SFINAE to determine if the passed in type is indeed an iterator
template<class It> class is_iterator_impl;
template<class It, bool check = is_iterator_impl<It>::value> struct is_iterator { typedef void type; };
template<class It> struct is_iterator<It*, false> { typedef void type; };
template<class It> struct is_iterator<It, false> { };
public:
template<class It> Carray(It first, It last, typename is_iterator<It>::type *dummy = 0);
};
template<class T>
template<class It>
Carray<T>::Carray(It first, It last, typename Carray<T>::is_iterator<It>::type *dummy) {
// create array from 2 iterators - ERROR IN THIS DEFINITION
}
template<class T>
template<class It>
class Carray<T>::is_iterator_impl {
private:
typedef char yes[1];
typedef char no[2];
template<class C>
static yes& _test(typename C::iterator_category*);
template<class>
static no& _test(...);
public:
static const bool value = sizeof(_test<It>(0)) == sizeof(yes);
};
我正在使用g ++ 4.5.5。
没有找到相关结果
已邀请:
2 个回复
扭湘阀柿蹄
关键字(
构造函数参数):
庞协腿宛炯
第一行末没有分号,只是一个猜测。