Stripped down to the bare minimum, here's the code I'm trying to compile:
template<class T>
class B
{
protected:
std::vector<typename T::I> v;
public:
template<class... Args>
void add(Args... args )
{
this->v.emplace_back(std::forward<Args>(args)...);
}
typename T::I get(int i)
{
return this->v[i];
}
};
class D : public B<D>
{
public:
typedef std::string I;
};
If I instantiate D
and try to compile this in g++
, it complains:
error: invalid use of incomplete type ‘class D’
std::vector<typename T::I> v;
and adds a note,
note: forward declaration of ‘class D’
class D : public B<D>
If I try clang++
instead, I get a different error:
error: no type named 'I' in 'D'
std::vector<typename T::I> v;
I'm sure I'm just doing something silly here but I can't seem to figure it out.