manpagez: man pages & more
info octave
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

33.4.3 Precedence of Objects

Many functions and operators take two or more arguments and so the case can easily arise that these functions are called with objects of different classes. It is therefore necessary to determine the precedence of which method of which class to call when there are mixed objects given to a function or operator. To do this the superiorto and inferiorto functions can be used

Built-in Function: superiorto (class_name, …)

When called from a class constructor, mark the object currently constructed as having a higher precedence than class_name. More that one such class can be specified in a single call. This function may only be called from a class constructor.

Built-in Function: inferiorto (class_name, …)

When called from a class constructor, mark the object currently constructed as having a lower precedence than class_name. More that one such class can be specified in a single call. This function may only be called from a class constructor.

For example with our polynomial class consider the case

 
2 * polynomial ([1, 0, 1]);

That mixes an object of the class "double" with an object of the class "polynomial". In this case we like to ensure that the return type of the above is of the type "polynomial" and so we use the superiorto function in the class constructor. In particular our polynomial class constructor would be modified to be

Note that user classes always have higher precedence than built-in Octave types. So in fact marking our polynomial class higher than the "double" class is in fact not necessary.


© manpagez.com 2000-2024
Individual documents may contain additional copyright information.