How to put a subclass object in an array of superclass objects?
이전 댓글 표시
In my code, I have two kinds of networks:
classdef Network <handle classdef NetworkMatrix <Network
and one 'holder class': classdef MetaNetwork <handle
which stores Networks (among other things). The holder class has methods to get networks by ID from an internal Map() and a method to get Networks from an array of other Networks.
I use the network matrix class to do some specific matrix alegbra and other operations on these networks, and it updates the map object just fine. However, when I stick a network in the internal network array the code creates a new Network, rather than just creating a reference to the NetworkMatrix object. Therefore, I lose any changes in the networkMatrix that occurs after the Network was initialized.
Question 1: Can I stick a subclass in an array of superclass objects instead of creating a new instance of the superclass object?
Question 2: (Assuming the answer to 1 is no) Can I change the way it pulls out objects without converitng the internal Network Array to a cell array that contains only networks and modifying all of the indexing to cell indexing?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Methods에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!