fork download
  1. #include <string>
  2. #include <memory>
  3. #include <cassert>
  4. #include <iostream>
  5.  
  6. class A
  7. {
  8. public:
  9. virtual ~A() = default;
  10. virtual std::string foo(int x) const
  11. {
  12. return "A";
  13. }
  14. };
  15.  
  16. void testA()
  17. {
  18. A a;
  19. assert(a.foo(10) == "A");
  20. }
  21.  
  22. class B: public A
  23. {
  24. public:
  25. std::string foo() const override
  26. {
  27. return "B";
  28. }
  29. };
  30.  
  31. void testB()
  32. {
  33. B b;
  34. assert(b.foo() == "B");
  35. }
  36.  
  37. void real_code()
  38. {
  39. std::unique_ptr<A> ptr(new B);
  40. std::cout << ptr->foo(10) << std::endl;
  41. }
  42.  
  43. int main() {
  44. // your code goes here
  45. testA();
  46. testB();
  47. real_code();
  48. return 0;
  49. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:25:17: error: ‘std::__cxx11::string B::foo() const’ marked ‘override’, but does not override
     std::string foo() const override
                 ^~~
stdout
Standard output is empty