When creating types with no additional features, I try to use using, rather than subclassing or using typedef.
I have a CRTP hierarchy where I am trying to propagate the concrete type up the tree.
GrandKid seems to compile fine. Is there a way to get GrandKid_2 to work?
ERROR MESSAGE
junk.cpp:18:26: error: ‘GrandKid_2’ was not declared in this scope
CODE
template<typename T>
struct Parent
{
};
template<typename T>
struct Child
: public Parent<T>
{
};
struct GrandKid :
public Child<GrandKid>
{
};
// using GrandKid_2 = Child<GrandKid_2>; // doesn't compile
int
main( int argv, char* argc[] )
{
GrandKid gk; // ok
}
using, liketypedef, creates an alias, not a new type. Therefore, you cannot use GrandKid_2 to define itself.You will surely need to create a new type :
By the way, do you really wantGrandKid_2to be its own child ? Maybe you meantusing GrandKid_2 = Child<GrandKid>