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. virtual std::string Foo() override
  18. {
  19. return "Derived";
  20. }
  21. };
  22.  
  23. template<> std::string Derived<float>::Foo() { return Base::Foo(); }
  24.  
  25. int main()
  26. {
  27. Derived<int> testInt;
  28. std::cout << testInt.Foo() << std::endl;
  29.  
  30. Derived<float> testFloat;
  31. std::cout << testFloat.Foo() << std::endl;//I would like this to print 'Base'
  32. }
  33.  
  34.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
Derived
Base