fork download
  1. class Cube
  2. {
  3. public:
  4. Cube();
  5. //bool hasSon; <- not needed, initialize the pointer and you can use that to test.
  6. Cube* son;
  7. void setSon(Cube* son);
  8. void draw();
  9. };
  10.  
  11. Cube::Cube() : son(nullptr)
  12. {}
  13.  
  14. void Cube::setSon(Cube* s)
  15. {
  16. son = s;
  17. }
  18.  
  19. void Cube::draw()
  20. {
  21. if(son)
  22. son->draw();
  23. }
  24.  
  25.  
  26. int main()
  27. {
  28. Cube* base = new Cube();
  29. Cube* base2 = new Cube();
  30. base->setSon(base2);
  31. base->draw();
  32. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
Standard output is empty