It's possible, IIRC. To change () but not {} and '.', write your subsref method to pass those other cases along to the builtin subsref from within your overloaded subsref, instead of trying to explicitly call the builtin from outside.function B = subsref(A, S) % Handle the first indexing on your obj itself switch S(1).type case '()' B = % ... do your custom "()" behavior ... otherwise % Enable normal "." and "{}" behavior B = builtin('subsref', A, S(1)) end end % Handle "chaining" (not sure this part is fully correct; it is tricky) orig_B = B; % hold on to a copy for debugging purposes if numel(S) > 1 B = subsref(B, S(2:end)); % regular call, not "builtin", to support overrides endend(如果builtin调用不起作用,则可以直接使用直接使用.和{}的情况,因为在类定义中忽略了subsref重载.)(And if that builtin call doesn't work, you can just put in cases that use . and {} directly, because the subsref overload is ignored inside the class definition.)要使其完全起作用,您可能需要将B更改为varargout,并在()"情况下添加链接行为.To make it fully functional, you may need to change B to a varargout, and add chaining behavior in to the "()" case. 这篇关于为什么我不能对重载subsref的类使用内置函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-29 05:45