fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class FeaturesExample {};
  5. class Example : public FeaturesExample {};
  6.  
  7. template<typename D>
  8. class Base {
  9. public:
  10. virtual float getFloat(const typename D::ExampleType* ex) const = 0;
  11. float getFloat(const FeaturesExample& ex) const {
  12. get(reinterpret_cast<typename D::ExampleType>(&ex));
  13. }
  14. float (Base::*getFloatImplPtr_)(const FeaturesExample& ex) const;
  15. float getFloatImpl_(const FeaturesExample& ex) const {
  16. return 0.0;
  17. }
  18. };
  19.  
  20. class Derived : public Base<Derived> {
  21. public:
  22. typedef ExampleType = Example;
  23. virtual float getFloatImpl(const Example* ex) override {
  24. return 1.0;
  25. }
  26. };
  27. int main() {
  28. FeaturesExample ex;
  29. Derived derived;
  30. auto f = derived.getFloat(ex);
  31. std::cout << f << std::endl;
  32. return 0;
  33. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘class Base<Derived>’:
prog.cpp:20:24:   required from here
prog.cpp:10:17: error: invalid use of incomplete type ‘class Derived’
   virtual float getFloat(const typename D::ExampleType* ex) const = 0;
                 ^~~~~~~~
prog.cpp:20:7: note: forward declaration of ‘class Derived’
 class Derived : public Base<Derived> {
       ^~~~~~~
prog.cpp:22:11: error: ‘ExampleType’ does not name a type
   typedef ExampleType = Example;
           ^~~~~~~~~~~
prog.cpp:23:17: error: ‘virtual float Derived::getFloatImpl(const Example*)’ marked ‘override’, but does not override
   virtual float getFloatImpl(const Example* ex) override {
                 ^~~~~~~~~~~~
prog.cpp: In instantiation of ‘float Base<D>::getFloat(const FeaturesExample&) const [with D = Derived]’:
prog.cpp:30:30:   required from here
prog.cpp:12:8: error: no type named ‘ExampleType’ in ‘class Derived’
    get(reinterpret_cast<typename D::ExampleType>(&ex));
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:12:7: error: ‘get’ was not declared in this scope
    get(reinterpret_cast<typename D::ExampleType>(&ex));
    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stdout

Standard output is empty