필터 지우기
필터 지우기

oop: how to switch between passing by reference and value

조회 수: 8 (최근 30일)
Herbert
Herbert 2013년 4월 25일
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!

채택된 답변

Daniel Shub
Daniel Shub 2013년 4월 25일
Copy Method for Handle Classes
Handle classes can derive copy functionality from the matlab.mixin.Copyable class. Class designers should investigate the use of this class in their class hierarchy design

추가 답변 (1개)

Matt J
Matt J 2013년 4월 25일
편집: Matt J 2013년 4월 25일
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.

카테고리

Help CenterFile Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by