The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Inheritance from classes withina package
Replies: 7   Last Post: May 24, 2013 3:57 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Steven Lord

Posts: 18,038
Registered: 12/7/04
Re: Inheritance from classes withina package
Posted: May 23, 2013 11:13 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Ron Lu" <> wrote in message
> "Nick Clark" wrote in message <h9dqf5$e15$>...
>> Hi all,
>> I have a query regarding inheritance of one class by another within a
>> package. For example, classB < classA within package mypack. From outside
>> the package directory I type:
>> import mypack.*
>> x = classB
>> . . then I get an error saying that classA cannot be accessed. I can
>> resolve this by making classB < myclass.classA at the top of the classdef
>> of classB. However, this seems like a bit of a clunky 'duct tape' kind of
>> work around. It also causes problems when trying to display the
>> documentation about the classes which are linked in blue from the disp
>> command.
>> What is the recommended elegant method for inheritance within a package?

> Anyone can help?
> I ran into the exact same problem.
> I already finished all my classes and now want to put them into different
> packages. And I HAVE TO add those import statements everywhere, or add
> packageName.Class* to let the class know where to find dependencies in the
> same package.

That is correct.

> Is there a way to work around?

No. Packages define a namespace, and the package name is sort of part of the
name of the class.

As a concrete example, if you had this directory structure (with mydirectory
on the path):


and you wanted to create an instance of the class defined in the classB.m
file inside +myPack from within the classA.m file, you would need to use
mypack.classB. If instead you wanted to instantiate an instance of the
mydirectory\classB.m class, you would simply use classB. [If you imported
mypack.classB inside classA.m, I don't believe you'd be able to access the
classB class defined outside the package in the function in which you

Steve Lord
To contact Technical Support use the Contact Us link on

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.