fork download
  1. #include <stdio.h>
  2.  
  3. class Base
  4. {
  5. public:
  6. Base() {}
  7. virtual ~Base(){}
  8.  
  9. virtual bool match( const void *data ) const { return false; }
  10. };
  11.  
  12. template <class Type>
  13. class Derived: public Base
  14. {
  15. public:
  16. Derived():Base() {}
  17. ~Derived() override{}
  18.  
  19. virtual bool match( const Type *data ) const override { return true; }
  20. };
  21.  
  22. int main(int argc, char **argv)
  23. {
  24. Derived<int> *d = new Derived<int>();
  25. Base *b = d;
  26.  
  27. int i;
  28. printf("B match = %s\n",b->match(&i)?"True":"False");
  29. printf("D match = %s\n",d->match(&i)?"True":"False");
  30. }
  31.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'class Derived<int>':
prog.cpp:24:39:   required from here
prog.cpp:19:20: error: 'bool Derived<Type>::match(const Type*) const [with Type = int]' marked 'override', but does not override
       virtual bool match( const Type *data ) const override { return true; }
                    ^
stdout
Standard output is empty