fork download
class Cube
{
public:
    Cube();
    //bool hasSon; <- not needed, initialize the pointer and you can use that to test.
    Cube* son;
    void setSon(Cube* son);
    void draw();
};

Cube::Cube() : son(nullptr)
{}

void Cube::setSon(Cube* s)
{
    son = s;
}

void Cube::draw() 
{
	if(son) 
		son->draw();
}


int main()
{
	Cube* base = new Cube();
	Cube* base2 = new Cube();
	base->setSon(base2);
	base->draw();
}
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
Standard output is empty