在此使用"this".在每个MATLAB类中 [英] The use of "this" in every MATLAB class

查看:453
本文介绍了在此使用"this".在每个MATLAB类中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在MATLAB的每个类中我都必须使用"this"?我认为在C ++中,仅在需要时才需要使用"this".在MATLAB中也是如此吗?

Why is that in every class in MATLAB I must use "this"? I think that in C++ I don't need to use "this", only if I want to. Is this also the case in MATLAB?

推荐答案

简而言之,您必须使用某种显式引用.

首先,与在C ++/C#/Java中将其命名为 this 的方式不同,您可以使用任何所需的名称. 必须使用显式调用的原因是 Matlab设计者的决定. 这个想法是为了支持对对象的Matlab向量运算,就好像它们是 结构.以下是上面链接的片段:

First of all, unlike in C++/C#/Java where it is named this, you can use any name you want. The reason that you must use explicit calls is Matlab designers decision. The idea was to support Matlab vector operations on objects, as if they are structs. The following is a fragment from the link above:

虽然带有隐式对象参数的语言提供了"this"关键字 访问隐式对象,它们通常不需要您访问 通过此"属性.如果MATLAB具有隐式属性,则逻辑 对基于数组的对象的扩展将是不进行任何索引:
S = S +(k).Value;

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设计人员并未选择这种方法.

Following the good comment of @AndrewJanke, I would like to add that MATLAB could have had this as implicit reference, and only force to use it in indexing of array-based objects. Nevertheless, this approach was not chosen by MATLAB designers.

这篇关于在此使用"this".在每个MATLAB类中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆