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 D::ExampleType* ex) const = 0;
  11. float getFloat(const FeaturesExample& ex) const {
  12. get(reinterpret_cast<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. float getFloatImpl(const Example* ex) {
  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 16064KB
stdin
Standard input is empty
compilation info
prog.cpp:10:32: error: need ‘typename’ before ‘D::ExampleType’ because ‘D’ is a dependent scope
   virtual float getFloat(const D::ExampleType* ex) const = 0;
                                ^
prog.cpp: In member function ‘float Base<D>::getFloat(const FeaturesExample&) const’:
prog.cpp:12:25: error: need ‘typename’ before ‘D::ExampleType’ because ‘D’ is a dependent scope
    get(reinterpret_cast<D::ExampleType>(&ex));
                         ^
prog.cpp:12:45: error: there are no arguments to ‘get’ that depend on a template parameter, so a declaration of ‘get’ must be available [-fpermissive]
    get(reinterpret_cast<D::ExampleType>(&ex));
                                             ^
prog.cpp:12:45: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
prog.cpp: At global scope:
prog.cpp:22:11: error: ‘ExampleType’ does not name a type
   typedef ExampleType = Example;
           ^~~~~~~~~~~
prog.cpp: In function ‘int main()’:
prog.cpp:29:10: error: cannot declare variable ‘derived’ to be of abstract type ‘Derived’
  Derived derived;
          ^~~~~~~
prog.cpp:20:7: note:   because the following virtual functions are pure within ‘Derived’:
 class Derived : public Base<Derived> {
       ^~~~~~~
prog.cpp:10:17: note: 	float Base<D>::getFloat(const int*) const [with D = Derived]
   virtual float getFloat(const D::ExampleType* ex) const = 0;
                 ^~~~~~~~
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:45: error: ‘get’ was not declared in this scope
    get(reinterpret_cast<D::ExampleType>(&ex));
                                             ^
stdout

Standard output is empty