Hierarchy Parent/Child from same class
조회 수: 5 (최근 30일)
이전 댓글 표시
I would like to add Parents and Childs between object of the same class.
Can I create properties 'Parent' and 'Child' with method setParent
댓글 수: 0
답변 (1개)
Steven Lord
2025년 3월 11일
I would like to add Parents and Childs between object of the same class.
Do you mean you're writing a class and you want each instance to have properties Parent and Child (or Parents and Children?) that can contain another instance of the class? [How many parents and how many children would you need/want an instance of the class to support?]
Would you also need to allow Parent and/or Child to contain something other than an instance of the class, to reflect that an object has no parent and/or no children?
Can I create properties 'Parent' and 'Child' with method setParent
There's no function named setParent in MATLAB. [A few classes in MathWorks products have defined such a method, but I haven't checked to see what if anything those methods are doing in addition to setting a property.]
which -all setParent
But you can have classes with properties that contain other objects. See for example the linked list class example in the documentation. Before you write such a class, you probably want to read this other documentation page as well.
You could define a method named setParent or a property set method named set.Parent if you wanted, but often you don't need to. You could use regular indexing operations to set or get the property value, as shown in the Property Access Syntax section on this documentation page.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!