[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: passing by reference
From: |
Paul Johnson |
Subject: |
Re: passing by reference |
Date: |
Thu, 24 Feb 2000 12:39:13 -0600 |
I'm just going to restructure this sim so I don't have to pass by
reference, but it still niggles me that this does not work:
"Marcus G. Daniels" wrote:
>
> >>>>> "PJ" == Paul Johnson <address@hidden> writes:
>
> PJ> I saw after some study that I probably need to declare the method
> PJ> like so: [..]
>
> That latter one is right, but you still have to pass "&proposal",
That gives me:
ModelSwarm.m: In function `-[ModelSwarm buildActions]':
ModelSwarm.m:157: warning: passing arg 4 of `createActionTo:message:::'
from incompatible pointer type
>From ModelSwarm.m:
[modelActions createActionTo: aSetter message: M(makeProp:to:):
current: &proposal];
Setter.h has:
-(id) makeProp: x to: (id *) p ;
-(id) makeProp: x to: (id *) ptr {
id p;
//here are steps *that work* and do create the new object p
dimarray newpos;
newpos[0]=0;
newpos[1]=0;
p = [PolicyPoint createBegin: [self getZone] ];
[p setWorld: world];
p= [p createEnd];
[p setPos: newpos];
[p setPolicyColor: 2];
diff=[aNormalDist getDoubleSample];
if (diff <= -2) deltaTheta = -0.5* widthOfSearch;
if (diff >= 2) deltaTheta = 0.5 * widthOfSearch;
if (diff > -2 && diff < 2) deltaTheta = (diff / 4.0) *
widthOfSearch;
angle= newangle + deltaTheta;
distance= [uniformDblRand getDoubleWithMin: 0 withMax:
+longestStep];
newpos[0]= [x getPolX] + distance*cos(angle*M_PI);
newpos[1]= [x getPolY] + distance*sin(angle*M_PI);
[p setPos: newpos];
[p sayHi]; //confirms p exists, printfs values
*ptr = p; //tries to pass back by reference
return self;
}
--
Paul E. Johnson email: address@hidden
Dept. of Political Science http://lark.cc.ukans.edu/~pauljohn
University of Kansas Office: (785) 864-9086
Lawrence, Kansas 66045 FAX: (785) 864-5700
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.