Difficulty foor running a class

2 ビュー (過去 30 日間)
elias BITAR
elias BITAR 2018 年 9 月 23 日
コメント済み: Walter Roberson 2018 年 9 月 30 日
I copied an example as showed in Matlab examples presentation but I get the following message classdef BasicClass ↑ Error: Illegal use of reserved keyword "classdef". Please can you help to run a class example Regards
  2 件のコメント
Stephan
Stephan 2018 年 9 月 23 日
Please provide the code you have tried so far.
Walter Roberson
Walter Roberson 2018 年 9 月 23 日
I speculate that you did not store the classdef in a separate file named after the class to be created.

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

回答 (3 件)

Arun Mathamkode
Arun Mathamkode 2018 年 9 月 27 日
As Walter Roberson pointed out, please make sure that you store the classdef in a separate file with the same name as the class name. Also please make sure that you didn't miss any end statements while copying the sample code.

elias BITAR
elias BITAR 2018 年 9 月 27 日
編集済み: Walter Roberson 2018 年 9 月 27 日
Many thanks for yor answer I stored the classdef in a separate file with the same name ( I make a copy of an example )
classdef (Sealed) MyClass < handle
properties (Access = private)
Prop1 = datenum(date)
end
properties
Prop2
end
methods
function obj = MyClass(x)
obj.Prop2 = x;
end
end
methods (Access = {?MyOtherClass})
function d = myMethod(obj)
d = obj.Prop1 + x;
end
end
events (ListenAccess = protected)
StateChanged
end
end
and here is the comment
classdef (Sealed) MyClass < handle
Error: Illegal use of reserved keyword "classdef".
Best reagards E BITAR
  1 件のコメント
Walter Roberson
Walter Roberson 2018 年 9 月 27 日
When I store the noted code in MyClass.m then I do not encounter any error in R2018a or R2018b.
Could you attach a copy of the MyClass.m that you are having difficulty with? Not paste but attach: I want to check it for special characters.

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


elias BITAR
elias BITAR 2018 年 9 月 30 日
You find enclosed file Regards
  1 件のコメント
Walter Roberson
Walter Roberson 2018 年 9 月 30 日
This new version is not < handle and leads to the editor error that events can only be defined for handle classes.

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

カテゴリ

Help Center および File ExchangeConstruct and Work with Object Arrays についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by