comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: overload init function in class/object ?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: overload init function in class/object ? [message #34988 is a reply to message #34986] Tue, 06 May 2003 12:55 Go to previous messageGo to previous message
Mark Hadfield is currently offline  Mark Hadfield
Messages: 783
Registered: May 1995
Senior Member
"paul wisehart" <wisehart@runbox.com> wrote in message
news:slrnbbg37q.2t7.wisehart@stingray.mcst.ssai.biz...
> I was under the assumption that you could overload the
> init function of an object.
>
> However, it doesn't work for me.
>
> In the below example I get an error if I try:
> IDL>o = obj_new('obj')
>
> Yet this works:
> IDL>o = obj_new('obj','test')
>
> I wanna be able to overload my init functions!
> Please tell me I'm doing something wrong.
>
>
> ;--- obj__define.pro -------------------
>
> function obj::init
> compile_opt idl2
> return, 1
> end
> ;-----------------------
> function obj::init, p1
> compile_opt idl2
> print, p1
> return, 1
> end
> ...

You can't overload a function in this way in IDL. When IDL compiles your
obj__define.pro the second version of obj::init will *replace* the first.
However IDL allows optional parameters, so the way to handle this in IDL is
something like

function obj::init, p1
compile_opt idl2
if n_elements(p1) gt 0 then print, p1
return, 1
end

The exact form of the test for the presence of the p1 positional parameter
depends on what you want to do with it; "if n_elements(p1) gt 0" is
generally what you want for input parameters.

--
Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
m.hadfield@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: sec : U Re: checking for Demo mode
Next Topic: Interpolation from a regular to an irregular grid?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Oct 12 11:04:33 PDT 2025

Total time taken to generate the page: 0.24168 seconds