필터 지우기
필터 지우기

Calling one method from another method

조회 수: 4 (최근 30일)
Michaël
Michaël 2016년 3월 16일
편집: per isakson 2016년 3월 19일
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
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
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개)

카테고리

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