Is the Abstract keyword needed to make a method abstract?

4 ビュー (過去 30 日間)
per isakson
per isakson 2021 年 9 月 17 日
コメント済み: per isakson 2021 年 9 月 18 日
Is this correct Matlab syntax
classdef MyClass
methods
outarg = my_method( this, inarg );
end
end
R2018b accepts it. Assuming this class definition is correct
  • is MyClass abstract?
  • is the method, my_method, abstract?
meta.class reports that .Abstract==false for both.
  1 件のコメント
per isakson
per isakson 2021 年 9 月 18 日
編集済み: per isakson 2021 年 9 月 18 日
Addendum: "Run in R2021a" can't execute these lines in the question, since the class definition causes an error
meta_class = meta.class.fromName( 'MyClass' );
meta_class.Abstract
ans = logical
0
meta_class.MethodList(1).Name
ans = 'my_method'
meta_class.MethodList(1).Abstract
ans = logical
0

サインインしてコメントする。

採用された回答

Steven Lord
Steven Lord 2021 年 9 月 18 日
That is valid syntax, but not for making my_method an Abstract method. What you've written tells MATLAB that my_method is implemented in a separate file, not in the classdef file for MyClass.
See this documentation page for more information on how to declare a method as Abstract.
classdef MyClass
methods (Abstract)
outarg = my_method( this, inarg );
end
end
  1 件のコメント
per isakson
per isakson 2021 年 9 月 18 日
@Steven Lord, thank you for the answer. I had forgotten (I never use separate files).
However, that means that MyClass.m needs to be in a class folder named, @MyClass.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDebugging and Analysis についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by