Why does overridng the handle delete method and setting it to hidden cause a warning to be generated?

5 次查看(过去 30 天)
Background; I have a reasonably complex set of objects, and a base of 6-7 people interested in them. I've read (anecdotally) that the primary way people explore API's is via tab completion.
I don't want generic matlab handle methods confusing people with what each object does, as opposed to the nature of it being an object. Therefore I want to hide certain methods, for example, the delete method.
classdef SomeClass < handle
methods(Hidden, Access = public)
function delete(varargin)
delete@handle(varargin{:});
end
end
end
Now, this appears to generate a warning;
Warning: The following error was caught while executing 'SomeClass' class destructor:
Method 'delete' is not defined for class 'SomeClass' or is removed from MATLAB's search path.
> In restoredefaultpath (line 52)
In something (line 2)
This method is definitely defined. Can anyone offer feedback on what's happening here, as it appears illogical to me?
  1 个评论
Adam
Adam 2017-8-21
编辑:Adam 2017-8-21
I don't get any warnings when I create and then delete an object of that class (in R2017a). Are you sure you cleared all objects of the class before making your changes? What is 'something' and more specifically what is it that is on line 2 that causes the error?

请先登录,再进行评论。

回答(1 个)

Simon Parten
Simon Parten 2017-8-21
Adam is quite right that this object is part of a deeper chain.
I don't understand why, but I couldn't get a simply example to work. However, changing the code to include an output argument... i.e.
classdef SomeClass < handle
methods(Hidden, Access = public)
function obj = delete(varargin)
obj = delete@handle(varargin{:});
end
end
end
Apears to solve the problem...

类别

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