fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A {
  5. public:
  6. A() {
  7. cout << "A created" << endl;
  8. }
  9. virtual ~A() {
  10. cout << "A deleted" << endl;
  11. }
  12. };
  13.  
  14. class B : public A {
  15. public:
  16. B() {
  17. cout << "B created" << endl;
  18. }
  19.  
  20. ~B() {
  21. cout << "B deleted" << endl;
  22. }
  23. };
  24.  
  25. int main() {
  26. // your code goes here
  27.  
  28. A* obj = new B();
  29.  
  30. long test = (long)obj;
  31.  
  32. delete (A*)test;
  33. return 0;
  34. }
Success #stdin #stdout 0s 4404KB
stdin
Standard input is empty
stdout
A created
B created
B deleted
A deleted