fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. class IInterface
  5. {
  6. public:
  7. virtual bool Check(const char* str) = 0;
  8. };
  9.  
  10. template<class T>
  11. class A : public IInterface
  12. {
  13. public:
  14. virtual bool Check(const char* str) { return false; } //1
  15. };
  16.  
  17. template<>
  18. class A<int> : public IInterface
  19. {
  20. public:
  21. virtual bool Check(const char* str) { return true; } //2
  22. };
  23.  
  24. int main()
  25. {
  26. std::unique_ptr<IInterface> p(new A<char>);
  27. std::cout << p->Check("abc") << std::endl;
  28. std::unique_ptr<IInterface> p1(new A<int>);
  29. std::cout << p1->Check("abc") << std::endl;
  30.  
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
0
1