oop: how to switch between passing by reference and value
显示 更早的评论
Hi all,
i've a class that inherits the "handle" class, objects therefore always passed by reference. But now I want to copy an array of objects of this class such that i can modify the original and the copy seperately. Is there any easy way to be able to decide between copying and object and passing it by reference?
Thank you!
采纳的回答
更多回答(1 个)
When you want an independent copy of a handle object, call the constructor to create a new instance of the class. Then, if necessary, copy the data over one property at a time. You could write a class method e.g., called clone(), to automate this for you.
类别
在 帮助中心 和 File Exchange 中查找有关 Handle Classes 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!