単純な形式の CRTP (Curiously Recurring Template Pattern) を使用しようとしています。いくつかのクラスがあり、それぞれにいくつかの関連クラスがあり、それらを結合する手段が必要です (たとえば、Widget のようなクラスがあります)。関連するクラス WidgetHandle、DoobryHandle、および WhatsitHandle を持つ Doobry および Whatsit)。
継承元として使用している各クラスはtypedefをBase
追加して、基本クラスがそれを として参照できるようにします。value_type
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;
}
ただし、コンパイル エラーが発生します。
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'
これは VS2010 の場合ですが、clang で同様のエラーが発生します。ここで何が欠けていますか?