Programming Previous page   Next Page

Object Precedence

Object precedence is a means to resolve the question of which of possibly many versions of an operator or function to call in a given situation. Object precedence enables you to control the behavior of expressions containing different classes of objects. For example, consider the expression

Ordinarily, MATLAB assumes that the objects have equal precedence and calls the method associated with the leftmost object. However, there are two exceptions:

For example, in the section Example -- A Polynomial Class the polynom class defines a plus method that enables addition of polynom objects. Given the polynom object p

The expression,

calls the polynom plus method (which converts the double, 1, to a polynom object, and then adds it to p). The user-defined polynom class has precedence over the MATLAB double class.


Previous page  The Portfolio subsref Method Specifying Precedence of User-Defined Classes Next page

© 1994-2005 The MathWorks, Inc.