fork download
  1. #include <iostream>
  2.  
  3. template < class Real >
  4. class ICovBase {
  5. bool isTrue;
  6. Real* This() {
  7. return static_cast < Real* > (this);
  8. }
  9. public:
  10. virtual bool operator() (int a) const {
  11. std::cout << "Base class () called\n";
  12. return true;
  13. };
  14. ICovBase(int a) {
  15. isTrue = This()->operator()(a);
  16. }
  17. virtual ~ICovBase() {};
  18. };
  19.  
  20. class Cov : public ICovBase < Cov > {
  21. public:
  22. bool operator () (int a) const {
  23. std::cout << "Child class () called\n";
  24. return (a > 0);
  25. }
  26. Cov(int a): ICovBase < Cov >(a) {
  27. }
  28. };
  29.  
  30. int main() {
  31. Cov test(5);
  32. }
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
Child class () called