Compile errors for simple CRTP case with dependent types
I'm trying to use a simple form of CRTP (Curiously Recurring Template
Pattern) as I've got several classes, each with several related classes,
and I want a means of binding them together (eg I've got classes like
Widget, Doobry and Whatsit, with related classes WidgetHandle,
DoobryHandle and WhatsitHandle).
Each class that I'm using 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'm getting 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, though I'm getting similar errors with clang. What am
I missing here?
No comments:
Post a Comment