【发布时间】:2012-08-28 20:48:10
【问题描述】:
我使用 MatLab 已经有一段时间了,但最近才开始使用 OOP。
我有一个类是一个简单的链表(它可以是任何东西)。在类中声明了一些方法。方法是否可以修改调用它们的实例?
instance.plotData() 不能修改实例的任何属性。
我必须返回该函数的实例才能对实例本身产生实际影响:
instance = instance.plotData();
这看起来真的很麻烦。有没有更好的方法来完成任务?
加法:
classdef handleTest < handle
properties
number
end
methods
function addNode(this)
a = length(this);
this(a+1) = handleTest;
end
end
end
如果我打电话:
x = handleTest
x.addNode()
那么x仍然只有一个节点。
【问题讨论】:
标签: function matlab object overloading