fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A {
  5. public:
  6. A() {
  7. log("Constructor A");
  8. }
  9. ~A() {
  10. log("Destructor A");
  11. }
  12. virtual void log(const char* message) {
  13. std::cout << "Log from A! (" << message << ")\n";
  14. }
  15. virtual void do_something() {
  16. log("Do something");
  17. }
  18. };
  19.  
  20. class B : public A{
  21. public:
  22. B() {
  23. log("Constructor B");
  24. }
  25. ~B() {
  26. log("Destructor B");
  27. }
  28. virtual void log(const char* message) {
  29. std::cout << "Log from B! (" << message << ")\n";
  30. }
  31. };
  32.  
  33. int main() {
  34. B b;
  35. b.do_something();
  36. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Log from A! (Constructor A)
Log from B! (Constructor B)
Log from B! (Do something)
Log from B! (Destructor B)
Log from A! (Destructor A)