为什么在 MATLAB 的每个类中我都必须使用“this”?我认为在 C++ 中我不需要使用“this”,只要我愿意。在 MATLAB 中也是这样吗?
最佳答案
简而言之,您必须使用某种显式引用。
首先,与在 C++/C#/Java 中将其命名为 this 不同,您可以使用任何您想要的名称。 您必须使用显式调用的原因是 Matlab designers decision . 这个想法是为了支持对对象的 Matlab 向量操作,就好像它们是 结构。以下是上面链接的片段:
While languages with an implicit object parameter provide a "this" keyword to access the implicit object, they usually do not require you to access a property through "this". If MATLAB had implicit properties, the logical extension to array-based objects would be to index into nothing:
S = S + (k).Value;
编辑: 在 @AndrewJanke 的好评之后,我想补充一点,MATLAB 可以将 this 作为隐式引用,并且只强制在基于数组的对象的索引中使用它。尽管如此,MATLAB 设计者并没有选择这种方法。
关于matlab - 在每个 MATLAB 类中使用 "this",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8885109/