I'm trying to understand why the following code snippet will not compile:
template <class Derived> struct Base {
const std::set<typename Derived::Foo> types() const { return theSet; }
std::set<typename Derived::Foo> theSet;
};
struct Derived : Base<Derived> {
enum Foo { X,Y,Z };
};
int main(int argc, char** argv) { Derived x; return 0; }
I get an error saying that the the line with types() const
is an invalid use of incomplete struct Derived
- but all it needs to know is that the type of the set is a Foo
enum so I'm not sure I understand the error or if there's a way around it that doesn't require me to make that set of type int
..
The full error from the compiler says:
error: invalid use of imcomplete type 'struct Derived'
const std::set<typename Derived::Foo> types() const {
error: forward declaration of 'struct Derived'
struct Derived : Base<Derived>