The class has no property or method named 'setCurncy'
5 ビュー (過去 30 日間)
古いコメントを表示
Hi. I have the following class. when I try to create an instance of that class
c=cBasket('aaa')
I get the following error message The class cBasket has no property or method named 'setCurncy'.
why does matlab not see the method setCurncy? Thanks, Chris
classdef cBasket
properties
curncy
end
methods
%%constructor
function obj = cBasket(symbol,date)
assert(nargin>0,'no symbol given');
if ~exist('date','var');
date=datestr(now,'yyyy-mm-dd');
end
obj.name = symbol;
obj.timestamp=date;
obj.curncy = cBasket.setCurncy(symbol);
end
%%methods getCurncy
function obj = setCurncy(symbol)
obj = 'xxx';
end % getCurncy
end
end
2 件のコメント
回答 (2 件)
Honglei Chen
2012 年 6 月 7 日
It is not a static method, so I think you should use
obj.curncy = obj.setCurncy(symbol);
2 件のコメント
Honglei Chen
2012 年 6 月 8 日
I'm not sure what you are trying to do, but I think you mean
function obj = setCurncy(obj,symbol)
obj.name = symbol;
end
Tim Szostakowski
2018 年 7 月 17 日
You can make your function Static, if you write "methods(Static)" in your methods definition:
classdef cBasket
properties
curncy
end
methods(Static) %%<<<<<<<<< HERE!!
%%constructor
function obj = cBasket(symbol,date)
assert(nargin>0,'no symbol given');
if ~exist('date','var');
date=datestr(now,'yyyy-mm-dd');
end
obj.name = symbol;
obj.timestamp=date;
obj.curncy = cBasket.setCurncy(symbol);
end
%%methods getCurncy
function obj = setCurncy(symbol)
obj = 'xxx';
end % getCurncy
end
end
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!