fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class FeaturesExample {};
  5. class Example : public FeaturesExample {};
  6.  
  7. class Base {
  8. public:
  9. float getFloat(const FeaturesExample& ex) const {
  10. return (this->*getFloatImplPtr_)(ex);
  11. }
  12. float (Base::*getFloatImplPtr_)(const FeaturesExample& ex) const;
  13. float getFloatImpl_(const FeaturesExample& ex) const {
  14. return 0.0;
  15. }
  16. };
  17. class Derived : public Base {
  18. public:
  19. float getFloatImpl(const Example& ex) {
  20. return 1.0;
  21. }
  22. };
  23. int main() {
  24. FeaturesExample ex;
  25. Derived derived;
  26. derived.getFloatImplPtr_ = (decltype(derived.getFloatImplPtr_))(&Derived::getFloatImpl);
  27. derived.getFloat();
  28. return 0;
  29. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:27:19: error: no matching function for call to ‘Derived::getFloat()’
  derived.getFloat();
                   ^
prog.cpp:9:9: note: candidate: float Base::getFloat(const FeaturesExample&) const
   float getFloat(const FeaturesExample& ex) const {
         ^~~~~~~~
prog.cpp:9:9: note:   candidate expects 1 argument, 0 provided
stdout
Standard output is empty