Unfortunately, this is not possible directly, because MyClass, at the time of creation Observable, it is not yet completed, and therefore you cannot access any typedefs. You can get around this by adding a small wrapper:
template< typename Type, typename Wrapper >
class Observable
{
public:
typename typedef Wrapper::TheObservedObject TheObject;
void Observe( TheObject& obj ) {}
};
struct MyClassWrapper{
class TheObservedObject
{
};
};
class MyClass : public Observable< MyClass, MyClassWrapper>
{
public:
typedef MyClassWrapper::TheObservedObject TheObservedObject;
};
Or just type TheObservedObjectout MyClass(Wrapper).
source
share