Reputation: 117846
Sorry for this very vague title, it's very hard to describe.
The error I'm stuck with is this, I have no idea what it means:
carray.h:176: error: ‘typename Carray<T, Allocator>::is_iterator’ names ‘template<class T, class Allocator> template<class I, bool check> struct Carray<T, Allocator>::is_iterator’, which is not a type
I have this snippet to detect if something is an iterator and use the correct overload (http://stackoverflow.com/questions/6050441/why-does-this-constructor-overload-resolve-incorrectly). This compiles:
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
}
};
Now I wanted to separate implementation from the declarations, and I tried this, but I got the error:
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);
};
I'm using g++ 4.5.5.
Upvotes: 1
Views: 808
Reputation: 208456
With these type of problems that are somehow obscure (i.e. there is quite a bit of code, and it is not simple to read in a first pass) you should provide a working (or rather failing example).
My guess is that you are missing a template
keyword (Carray
constructor argument):
typename Carray<T, Allocator>::template is_iterator<InputIterator>::type
// ^^^^^^^^
Upvotes: 3
Reputation: 9523
Check out the semicolon at the end of every line, it looks like you have written something like this:
template<class T, class Allocator>
template<class I, bool check> struct Carray<T, Allocator>::is_iterator
without semicolon at the end of the first line, just a guess.
Upvotes: -2