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

Home » Public Forums » archive » Re: What about real polymorphism ??
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: What about real polymorphism ?? [message #41981 is a reply to message #41980] Thu, 09 December 2004 08:57 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Antonio Santiago writes:

> Sorry, i think my english is little poor :)

It's good enough for this crowd. :-)

> In a language like java i can "cast" C2 object to a C1 object and
> invoque "datos". The result is the execution of method "datos" of the C2
> object.
>
> How can i do the same with IDL? It posible in IDL to cast to superclass?
>
> ----------------------------------------------------------
>
> Example:
>
> IDL> o1 = obj_new('c1')
> IDL> o2 = obj_new('c2')
> IDL> o1->datos
> clase1
> 1
>
> IDL> o2->datos
> class2
> 2
> thing 2
>
>
> I want to "cast" o2 from C2 to C1 class and invoque "datos". A real
> polymorphism "detects" that o2 really is an C2 object and that it had
> overriden "datos" method and invoque it.

I don't know a thing about JAVA, but didn't this just
DO what you want it to do? You invoked the DATOS method
on o2, IDL knows this is a c2 object, so called the correct
method. What did you want, if not that?

Now that I think about it, what may be confusing you
is how object methods get *attached* to objects. If you
create object c1 with a DATOS method. Then create object c2
by INHERITing c1, but do NOT create it with a DATOS method,
it will use the c1 DATOS method when DATOS is called. We
agree on this.

But now, if IN THAT SAME IDL SESSION, you create a DATOS method
for c2 (after you have already created an instance of c2 in that
IDL session), then when you call the DATOS method, the c1 DATOS
method will STILL be called! It is as if the c2 DATOS method
doesn't exist. You will have to do a .RESET to get the c2 DATOS
method attached to a c2 object. The IDL documentation is silent
on this little point. You learn it only by experience.

Could this be what is causing you problems? Otherwise, I think
IDL acts exactly like you hope it will act.

> To finshing, i think i answer my self :)

Ah, the secret of the IDL newsgroup. Reading is useless.
Understanding comes only from the act of hitting the SEND
button. :-)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
[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
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Stretching an image
Next Topic: ENVI and ROIs

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

Current Time: Fri Oct 10 18:38:06 PDT 2025

Total time taken to generate the page: 0.77292 seconds