What exactly are Handle Compatible Classes? Are they a combination of handle and non-handle classes?
4 ビュー (過去 30 日間)
古いコメントを表示
I read Handle Compatible Classes, the page say"Typically, when deriving a MATLAB® class from other classes, all the superclasses are handle classes, or none of them are handle classes. However, there are situations in which a class provides some utility that is used by both handle and nonhandle subclasses. Because it is not legal to combine handle and nonhandle classes, the author of the utility class must implement two distinct versions of the utility.
The solution is to use handle-compatible classes. You can use handle-compatible classes with handle classes when forming sets of superclasses. Designate a class as handle compatible by using the HandleCompatible class attribute."
I know “The HandleCompatible attribute is not inherited.”
I ran the following code,I found that the objects defined by A do not belong to any class! Why is this happening?
ta=A;
ty=isa(ta,'handle')
ty=isa(ta,'value')
ty=isa(ta,'HandleCompatible')
I ran the following code,tb do not belong to any class either! Why?
tb=B;
ty=isa(tb,'handle')
ty=isa(tb,'value')
ty=isa(tb,'HandleCompatible')
I ran the following code.Why can't I define objects for class C? I don't quite understand this error message.
c=C;
Error using C
If a class defines super-classes, all or none must be handle classes.
I have defined three classes, and the code is as follows:
classdef (HandleCompatible=true) A
properties
a
end
end
classdef B < A
properties
b
end
end
classdef C < B & handle
properties
c
end
end
0 件のコメント
採用された回答
Matt J
2023 年 8 月 28 日
編集済み: Matt J
2023 年 8 月 28 日
I found that the objects defined by A do not belong to any class! Why is this happening?
The syntax of of isa() is,
isa(object,classname)
but 'value' and "HandleCompatible' are not the names of classes. You cannot query whether an object is a value or handle compatible class this way.
Why can't I define objects for class C?
The handle compatibility of A is not inherited by B, see Handle Compatibility Rules
8 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Subclass Definition についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!