views:

61

answers:

3

i have a dynamically made prototype:

typedef double ICEDouble;
-(BOOL) getPosition:(SyDRpcInterfacePositionType)type longitude:(ICEDouble *)longitude latitude:(ICEDouble *)latitude;

and i would call it so, because i have no plan, how to do it in the right way:

NSNumber* longitudeReturn;
NSNumber** latitudeReturn;      
[prx getPosition:SyDRpcInterfaceMAPMATCHED longitude:longitudeReturn latitude:latitudeReturn];

the compiler says:

warning: passing argument 2 of 'getPosition:longitude:latitude:' from incompatible pointer type  
warning: passing argument 3 of 'getPosition:longitude:latitude:' from incompatible pointer type

not really surprising, but can anyone please tell me how to do it right ? maybe with a little explanation for a beginner ?

+3  A: 

Assuming ICEDouble is typedef'd to `double', it looks like the method you are calling has two 'out' parameters. It should be called like this:

double lat, long;
[prx getPosition:SyDRpcInterfaceMAPMATCHED longitude:&long latitude:&lat];

This is a common idiom when a method needs to return multiple values, without object overhead. If needed, you can then convert these to NSNumbers if you need them, via:

NSNumber * nLatitude = [NSNumber numberWithDouble:lat];
NSNumber * nLongitude = [NSNumber numberWithDouble:long];

Check the return type of getPosition: though. If it returns a BOOL you will want to check the result before using the returned values. Otherwise, lat and long will represent garbage values.

Jason
+2  A: 

Several things:

  1. The signature defines ICEDouble, you provide NSNumber.
  2. With NSNumber** latitudeReturn, you define a pointer to a pointer.

So I guess it should be

ICEDouble* longitudeReturn;
ICEDouble* latitudeReturn;      
[prx getPosition:SyDRpcInterfaceMAPMATCHED longitude:longitudeReturn latitude:latitudeReturn];
Felix Kling
A: 

and on this construct ?

    SyDRpcInterfaceNavInfos** datenSammlung;



    //-(BOOL) getGuidanceInfos:(SyDRpcInterfaceNavInfos **)infos;

    if([prx getGuidanceInfos:&datenSammlung]) {//further activities}

wether if i let the &, nor if i leave the end because of the extra pointer-*, the programm quits with both constellations at here. the SyDRpcInterfaceNavInfos is a struct.

nico
just had to initialize the struct... done and works now
nico