fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. class Base
  5. {
  6. public:
  7. virtual std::string Foo()
  8. {
  9. return "Base";
  10. }
  11. };
  12.  
  13. template <typename T>
  14. class Derived : public Base
  15. {
  16. public:
  17. typename std::enable_if<std::is_same<T, float>::value, std::string>::type
  18. virtual Foo() override
  19. {
  20. return "Derived";
  21. }
  22. };
  23.  
  24. int main()
  25. {
  26. Derived<int> testInt;
  27. std::cout << testInt.Foo() << std::endl;
  28.  
  29. Derived<float> testFloat;
  30. std::cout << testFloat.Foo() << std::endl;
  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:26:15:   required from here
prog.cpp:18:10: error: no type named ‘type’ in ‘struct std::enable_if<false, std::basic_string<char> >’
  virtual Foo() override
          ^
stdout
Standard output is empty