Bug: class field modified by reference
显示 更早的评论
There is a major bug in Matlab in which the field of a class is modified when passed as an function argument but not requested as an output if the calling function modifies the value internally. In the minimal example below: b.value is not the same before and after calling test.
b.value = 10;
b.value,
a = test(b);
b.value
function a = test(b)
a=1; b=b.value*10;
end
3 个评论
Walter Roberson
2018-6-1
I am not seeing anything when I test your code in R2018a.
If b was being modified by the code you post, then it would no longer be a struct (because you are writing over all of b), and b.value would then be a failure.
Your question talks about "field of a class", but your demonstration involves a struct rather than a class.
Antonio Mei
2018-6-1
Walter Roberson
2018-6-1
Please post actual example including classdef
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File 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!