using classdef, is it possible to mix run-time data access through the dot syntax with methods elegantly?

3 visualizaciones (últimos 30 días)
hi
i am developing a class (using classdef) that maintains a structure internally with fields that are instance-dependent. i want to provide direct access to these instance-dependent fields through object.fieldname syntax, so i use subsref and override fieldnames() so that tab completion works correctly.
trouble is, now all methods called using the syntax object.method() also result in calls to subsref, so i have to provide a case in subsref for every method of the class. this seems inelegant at best, and error prone at worst.
is there another way to achieve what i want?
thanks ben

Respuesta aceptada

David Young
David Young el 4 de Dic. de 2011
"Elegantly" is hard to do in this context, I think. There's some discussion of this kind of issue here.
  2 comentarios
Ben Mitch
Ben Mitch el 4 de Dic. de 2011
Thanks David. Seems there's a lot of murk around these sort of issues; I guess worse things happen at sea :).
David Young
David Young el 5 de Dic. de 2011
Yes - my own view is that the design of subsref() isn't as helpful as it could be.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by