fork download
  1. #include <iostream>
  2.  
  3. class Base {
  4. public:
  5. virtual void foo() { std::cout << "Base::foo()\n"; }
  6. virtual bool isDerived() const { return false; }
  7. };
  8.  
  9. class Derived : public Base {
  10. public:
  11. void foo() override { std::cout << "Derived::foo()\n"; }
  12. bool isDerived() const { return true; }
  13. };
  14.  
  15. int main() {
  16. Base* crrPos = new Derived;
  17. crrPos->foo();
  18. bool isDerived = crrPos->isDerived();
  19. std::cout << isDerived << '\n';
  20. delete crrPos;
  21. }
  22.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
Derived::foo()
1