help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to 'overload' functions


From: Paul Kienzle
Subject: Re: How to 'overload' functions
Date: Sun, 18 Jul 2004 17:59:22 -0400

Jia,

Use dispatch() from octave-forge.

Rename your function type_size, for whatever your
type is, and put the following PKG_ADD statement
in the file defining your type:

// PKG_ADD dispatch('size','type_size','type')

If your 'type' is a structure defined in m-files, you can use:

## PKG_ADD dispatch('size','type_size','struct')

then in type_size you can use the builtin 'size' function
builtin('size',s) if s.

This will only work once unfortunately. A short term
solution is to extend dispatch.cc  slightly so that
x=dispatch('size','struct') returns the dispatch function
rather than clearing it, and use dispatch('size','','struct')
or something like that to clear the dispatch.  Then
before defining the dispatch, you can save the
current dispatch in a global variable, and call the
current dispatch from within the function.  A better
solution, though, is to define a systematic way to
define new types from m-files.

Paul Kienzle
address@hidden

On Jul 18, 2004, at 5:00 PM, <address@hidden> wrote:

Hi

I want to write a function with the same name of 'size' as the
one already exsists in octave. In this new function, I will
calculate the size of a new data type, if the input is the new
data type. Otherwise, I will call the octave size function.

I implemented it in DLD function and run octave at the same
directory as it is.However, when I call 'size(x)' in octave,
it always call the octave size function instead of my DLD size
function. Can anyone tell me how to 'overload' functions and
how to specify which size function to run?

Thanks,

Jia



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------




-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]