Array of derived-class objects: Catch-22?

조회 수: 3 (최근 30일)
David Goldsmith
David Goldsmith 2011년 7월 20일
Hi! I'm trying to write an "intelligent" array extender--one that presents a single interface to extend numeric, character, cell, structure, and object arrays. I've succeeded w/ the first four, but am stuck on the last because the syntax I'm trying to use:
a(n+i).(prop) = item(i).(prop)
calls a's constructor w/ no arguments, so its c-tor has to handle the no argument case. However, if I do so as described in the help documentation, i.e., by encasing the body of the c-tor in an if nargin~=0 block, apparently I can't combine this w/ a derived class that calls its superclass c-tor, 'cause I get the error:
A constructor call to superclass <superclass name> is not a top-level statement.
(And if I try to get around this by relegating the if block to the superclass' c-tor, then the derived class' c-tor complains when the array builder calls its c-tor.)
Bug or "feature"? Workaround? Thanks!
OlyDLG

채택된 답변

David Goldsmith
David Goldsmith 2011년 7월 20일
OK, I think I found the answer (I guess it only makes sense that the more complicated my code becomes, the more of the help doc I'm going to have to read...): I have to provide default values for all my derived-class' properties in the properties def. section and then, in the no arguments case, provide default values for the superclass' c-tor arguments (if it doesn't also handle the no arguments case). I'll test this and reply if it doesn't work.

추가 답변 (1개)

David Goldsmith
David Goldsmith 2011년 7월 20일
OK, got it, sorry for the noise!

카테고리

Help CenterFile Exchange에서 Use COM Objects in MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by