我从 MATLAB 中的面向对象编程开始,我对如何最好地将对象传递给其他对象感到困惑,因为 MATLAB 没有静态类型定义。
我有三个不同的类,它们都包含一些常量。现在,我想在第三个类的方法中使用两个类中定义的常量——我应该怎么做?这些类没有层次结构。
所以,我在 C++ 中寻找类似#include 的东西。
问题如下图所示。如何编写“*Object1”和“*Object2”引用来访问 const1 和 const2?
classdef Object1
properties (Constant)
const1 = 100;
end
methods
function Obj1 = Object1()
end
end
classdef Object2
properties (Constant)
const2 = 200;
end
methods
function Obj2 = Object2()
end
end
classdef Object3
properties (Immutable)
property3
end
methods
function Obj3 = Object3()
Obj3.property3 = *Object1.const1 + *Object2.const2;
end
end