Answer the question
In order to leave comments, you need to log in
How to make a reaction to a method call on an object?
For example, there is such a hierarchy.
class Bomb{
void boom();
}
class Box{
vector <Bomb> bomb;
}
class Car{
vector<Box> box;
}
Answer the question
In order to leave comments, you need to log in
Each object must have a unique identifier. The bomb checks if there is an object in the affected area, after which the found object is removed. Those. in addition to the specified classes, you still need to make a class that controls the creation, deletion and search for objects by their identifier.
This topic is not about hierarchy and OOP.
And about algorithms and data structures. In their language, the question should sound like this.
- Given a tree of objects {Car}/{Box}/{Bomb}
- And when an event occurs at the leaf level of the tree, the entire Parents chain up to the Car level should be deleted.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question