Forward declaration of derived inner class
- by Loom
I ran into problem implementing some variations of factory method.
// from IFoo.h
struct IFoo {
struct IBar {
virtual ~IBar() = 0;
virtual void someMethod() = 0;
};
virtual IBar *createBar() = 0;
};
// from Foo.h
struct Foo : IFoo { // implementation of Foo, Bar in Foo.cpp
struct Bar : IBar {
virtual ~Bar();
virtual void someMethod();
};
virtual Bar *createBar(); // implemented in Foo.cpp
};
I'd like to place declaration of Foo::Bar in Foo.cpp. For now I cannot succeed:
struct Foo : IFoo {
//struct Bar; //1. error: invalid covariant return type
// for ‘virtual Foo::Bar*
//struct Bar : IBar; //2. error: expected ‘{’ before ‘;’ token
virtual Bar *createBar();
// virtual IBar *createBar(); // Is not acceptable by-design
};
Is there a trick to have just forward declaration of Boo in Foo.hpp and to have full declaration in Foo.cpp?