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.

 채택된 답변

Christopher Jones
Christopher Jones 2015년 12월 25일
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.

댓글 수: 1

Thanks so much for this. I ran into a similar issue and this solved it.

댓글을 달려면 로그인하십시오.

추가 답변 (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