Consider the following directory structure and that C:\magic
is the current MATLAB folder:
C:\magic
C:\magic\+wand
C:\magic\+hat
Now, wand
and hat
are MATLAB packages which may be loaded by import wand.*
and import hat.*
.
Consider that I may want to create an abstract class for hat inside the +hat
folder:
% C:\magic\+hat\Hat.m
classdef Hat < handle
% class implementation ...
end
and some child class:
% C:\magic\+hat\TopHat.m
classdef (Sealed) TopHat < Hat
% class implementation
methods
function this = TopHat()
this = this@Hat();
end
end
end
But when I do:
> import hat.*
> ha = TopHat()
I get the following error:
Error using hat.TopHat
The specified superclass 'Hat' contains a parse error or cannot be found
on MATLAB's search path, possibly shadowed by another file with the same name.
Nevertheless, I can do ha = Hat()
with no error.
What is possibly happening and what is the best solution to this issue?
Thanks in advance!
Try
classdef (Sealed) TopHat < hat.Hat
There's no "search-current-package-first"-routine in MATLAB (sorry for the bad name :>). So to refer to a class within a package you always have to carry the package name - even e.g. to refer to a static method of a class within its own classdef.