I wanted to create a template class that would provide generic means for a class to have a member m_Type
that designates some kind of type provided by the inheriting class. Consider this:
template<typename T>
struct TypeAttribute
{
T m_Type;
};
template<typename T>
struct TypeAttribute2
{
using Type = typename T::Type;
Type m_Type;
};
struct Foo : TypeAttribute<Foo::Type>
{
enum class Type
{
Type1
};
};
struct Bar : TypeAttribute2<Bar>
{
enum class Type
{
Type1
};
};
Both of these fail due to incomplete types (in the first case Foo::Type
and in the second Bar::Type
) which is understandable. Am I missing something trivial or is this just a wrong approach and I should move the nested types outside the classes (I simply wanted the classes to contain the relevant types inside themselves not to populate higher namespaces). Live demo here.