How can I combine two objects of different subclasses into the property of another class?
Mostra commenti meno recenti
Hello,
I explain the example so that it is better understood: I have a "board" class with a "player" attribute. This attribute is a list of different objects of the "human player" class. If I want to add to this list "player" objects of the class "player cpu" I get an error.
Risposta accettata
Più risposte (1)
Philip Borghesani
il 24 Mag 2018
1 voto
Two ways to do this:
- Make player a cell array instead of an array of of human players. This is the simplest solution but may not be the best in the long run.
- Derive "human player" and "player cpu" from a common base class that is heterogeneous
Categorie
Scopri di più su Software Development in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!