The base class in the CRTP pattern can access the member functions of the derived class, but it can't access a nested type in the derived class.
Why this difference?
To illustrate, consider the following piece of code:
template<typename Derived>
struct crtp_base
{
void crtp_method() { return static_cast<Derived&>(*this).method(); } // compiles
using crtp_type = typename Derived::type; // doesn't compile
};
struct X : public crtp_base<X>
{
void method() {}
using type = int;
};
int main()
{
}
crtp_type
causes a compilation error, while crtp_method
compiles fine, although both attempt to access something defined in the Derived
class. What is the C++ specification that explains that difference?