You can! Nope
(similar question)
I don't think that this can work. In order to define the class Derived
you need to know the base class ("it must be a complete type") first; to instantiate the template Base
into a class you need to have a type. Inner
however is only a type "inside" of Derived
; it's part of it's definition.
Definition of Derived ---needs---> Base<Derived::Inner>
^ |
|----------needs----------------|
Even an indirection does not help:
template<typename T>
class Base {};
template<template<class> class X, typename T>
struct UseInner : public X<typename T::Inner> {};
class Derived : UseInner<Base, Derived>
{
public: class Inner {};
};
In contrast to this, the CRTP works because there the template parameter can be an incomplete type ("no need to access internals").
Wrapping in a template doesn't work:
template<typename T>
class Base {};
template<template<class>class X>
struct Wrap
{
struct Derived : X<typename Derived::Inner> {
struct Inner {};
};
};
using RealDerived = typename Wrap<Base>::Derived;