How do I resolve this package subclass path error?

Hi all,
In R2014a, I've subclassed a class within a package hierarchy, where B subclasses A:
subclasstest/
└── +mypkg
└── +mysubpkg
├── @A
│   └── A.m
└── @B
└── B.m
My commands are:
cd subclasstest;
addpath(genpath(pwd));
import mypkg.mysubpkg.A
which A % /Users/cjones/subclasstest/+mypkg/+mysubpkg/@A/A.m % mypkg.mysubpkg.A constructor
a = A(1); % a = A with properties: x: 1 y: []
import mypkg.mysubpkg.B
which B % /Users/cjones/subclasstest/+mypkg/+mysubpkg/@B/B.m % mypkg.mysubpkg.B constructor
b = B(1,2); % Expecting B with properties x:1 y:2
Error using mypkg.mysubpkg.B
The specified superclass 'A' contains a parse error, cannot be found on MATLAB's search path, or is
shadowed by another file with the same name.
However, when I use the classes out of the package, I don't get the error:
subclasstest2/
├── A.m
└── B.m
With:
clear all; clear import;
cd ../subclasstest2/
addpath(genpath(pwd));
which A % /Users/cjones/subclasstest2/A.m % A constructor
a = A(1); % a = A with properties: x: 1 y: []
which B % /Users/cjones/subclasstest2/B.m % B constructor
b = B(1,2); % B with properties x:1 y:2
What am I doing wrong in the package hierarchy that would cause this error? I've seen this error message in many other postings after a bit of Googling, but I'm not seeing a clear answer. These classes use the 'classdef'-style syntax. Thanks much.

 采纳的回答

The issue here was that I was not subclassing with the correct syntax. Instead of using:
classdef B < A
% ...
end
I should have used:
classdef B < mypkg.mysubkg.A
% ...
end
I needed to use the fully qualified class name.

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Software Development 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by