C
C
CaskaProVid2020-05-10 13:52:27
C++ / C#
CaskaProVid, 2020-05-10 13:52:27

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;
}


When the boom method fires, the vector element from the Car object should be removed.
That is, the method of the Car class should work, which will remove this particular Box.
I hope I explained clearly.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
maaGames, 2020-05-10
@CaskaProVid

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.

M
mayton2019, 2020-05-10
@mayton2019

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 question

Ask a Question

731 491 924 answers to any question