swarm-support
[Top][All Lists]
Advanced

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

Casting an id type to a specific object type?


From: Jae Chan Oh
Subject: Casting an id type to a specific object type?
Date: Fri, 14 Mar 1997 01:23:46 -0500 (EST)

Hi Glen,
This question is in the same thread as the second question of my
last email about updateEnergy method in my program.

Say, in a method,
I have a delcation:

-myMethd {
(id) tgt;
bool status;

    if (((tgt = [world getObjectAtX: x1 Y: y1]) != nil))
        status = [tgt isItAlive];

//   some stuff .......

}

Let's say "isItAlive" is a method of "Person" type. I get core dump
at "status = [tgt isItAlive]" line since objc_msg_lookup
can't find the method. I have tried to declare tgt as pointer to
Person i.e.: Person * tgt. And tried many other things but no luck.

How do I cast tgt to Person type so it can recognize the method "isItAlive"?
Should using protocol would help? 
i.e. declaring tgt as "(id <PersonProtocol>)" tgt would help?
I'd like to avoid delcaring protocol if possible.

FYI, the following is gdb error messages after the crash:
(gdb) where
#0  objc_msg_lookup (receiver=0x368b00, op=0x278d10) at sarray.h:216
#1  0x41c2c in _i_Person__look (self=0x368880, _cmd=0x278b48) at Person.m:353
#2  0x404e0 in _i_Person__step (self=0x368880, _cmd=0x27934c) at Person.m:50


Thank you,

-Jae


reply via email to

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