Calling one method from another method
4 ビュー (過去 30 日間)
古いコメントを表示
Hello,
Two classes:
classdef first < handle
methods
function hello(obj)
disp('hello ok')
obj_second.bye
end
end
end
and
classdef second < handle
methods
function bye(obj)
disp('bye ok')
end
end
end
I'd like to be able to call obj_second.bye from obj_first.
Can you please help me?
Thank you very much
1 件のコメント
Guillaume
2016 年 3 月 17 日
I don't understand what you're trying to achieve here. What is obj_second (other than an object of class second)? Where does it come from? how does the class first know about it?
採用された回答
per isakson
2016 年 3 月 19 日
編集済み: per isakson
2016 年 3 月 19 日
Is this close to what you look for?
obj_second could have been passed as an argument to the constructor of first.
>> f = first;
>> f.hello
hello ok
bye ok
where
classdef first < handle
properties
obj_second
end
methods
function this = first()
this.obj_second = second;
end
function hello( this )
disp('hello ok')
this.obj_second.bye
end
end
end
and
classdef second < handle
methods
function bye( this )
disp('bye ok')
end
end
end
... and there other ways to call "one method from another method".
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および 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!