Overload subsref for getting and setting static properties

조회 수: 15 (최근 30일)
Joel Andersson
Joel Andersson 2014년 4월 14일
답변: Joel Andersson 2014년 4월 15일
If I have written a class MyClass, I can customize the behavior of expressions such as a.myProperty, a(4) where a is an instance of MyClass. As described in the documentation I do this by overloading subsref for MyClass.
But how can I in a similar way customize the behavior of the same operations applied to classes instead of class instances?
That is, how can I redefine the behavior of for example:
p = MyClass.MyStaticProperty;
Is there a static method equivalent to subsref?
Best regards, Joel
  댓글 수: 2
Sean de Wolski
Sean de Wolski 2014년 4월 14일
Why do you want that?
Joel Andersson
Joel Andersson 2014년 4월 14일
I am wrapping C++ code. I would like to be able to get and set static variables of the C++ class using a natural syntax.

댓글을 달려면 로그인하십시오.

채택된 답변

Joel Andersson
Joel Andersson 2014년 4월 15일
Non-constant static properties are not supported in MATLAB. Here is a good explaination why: http://stackoverflow.com/a/6453124/1203683. For the same reason mentioned there (e.g. that you do not want to redefine A.B = C), I guess redefining subsref/subsasgn is impossible.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by