    #include <iostream>

    template<class Derived>
    class CRTP {
    protected:
      Derived * derived_this() {
        return static_cast<Derived *>(this);
      }
    };
 
    template<class Derived>
    struct Parent : public CRTP<Derived> {
    private:
      using CRTP<Derived>::derived_this;
    public:
      int y() {
        return derived_this()->x();
      }
    };
 
    struct Child : public Parent<Child> {
      int x() {
        return 5;
      }
      int z() {
        return y();
      }
    };
 
    int main() {
      std::cout << Child().z() << std::endl;
      return 0;
    }
