fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Base{
  5. public:
  6. Base(){};
  7. virtual ~Base() {};
  8. virtual void foomethod()=0; //Marked as pure virtual
  9. };
  10.  
  11. class A : public Base{
  12. public:
  13. A(){}; //Ctor
  14. virtual ~A(){}; //Dtor
  15. void foomethod(){ cout << "Hello from A"; }
  16. };
  17. class B : public Base{
  18. public:
  19. B(){}; //Ctor
  20. virtual ~B(){}; //Dtor
  21. void foomethod(){ /* DO SOMETHING */ }
  22. };
  23.  
  24. int main() {
  25.  
  26. // Base obj; // Can't do that
  27. Base *obj = new A();
  28. obj->foomethod(); // A's one
  29. delete obj;
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
Hello from A