I am trying to use a simple CRTP (Curiously Recurring Template Pattern) form, as I have several classes, each of which has several related classes, and I want them to bind them together (for example, I have classes like Widget, Doobry and Whatsit , with the related classes WidgetHandle, DoobryHandle, and WhatsitHandle).
Each class that I use to inherit from Base adds a value_type typedef so that the base class can refer to it as typename TWrapper::value_type .
struct WidgetHandle {}; template <typename TWrapper> class Base { public: Base(typename TWrapper::value_type value_) : value(value_) {} typename TWrapper::value_type value; }; class Widget : public Base<Widget> { public: typedef WidgetHandle value_type; Widget(WidgetHandle value_) : Base<Widget>(value_) {} }; int main(int argc, char* argv[]) { Widget i(WidgetHandle()); return 0; }
However, I get compilation errors:
scratch1.cpp(10): error C2039: 'value_type' : is not a member of 'Widget' scratch1.cpp(16) : see declaration of 'Widget' scratch1.cpp : see reference to class template instantiation 'Base<TWrapper>' being compiled 1> with 1> [ 1> TWrapper=Widget 1> ] scratch1.cpp(10): error C2039: 'value_type' : is not a member of 'Widget'
This is with VS2010, although I get similar errors with clang. What am I missing here?
source share