#include #include class SceneGraph; class Entity { public: virtual void deleteE(SceneGraph* e); }; using namespace std; class Entity; class SceneGraph { public: void deleteE(Entity* e); void print(string s); }; class SpecialEntity: public Entity { public: virtual void deleteE(SceneGraph* e); }; void Entity::deleteE(SceneGraph* graph) { graph->print("entity::delete()"); } void SceneGraph::deleteE(Entity* e) { e->deleteE(this); } void SceneGraph::print(string s) { cout << s << "\n"; } void SpecialEntity::deleteE(SceneGraph* graph) { graph->print("SpecialEntity::delete()"); } int main() { Entity e; SpecialEntity f; SceneGraph* graph = new SceneGraph(); graph->deleteE(&e); graph->deleteE(&f); }