tags:

views:

618

answers:

1

Is there a way to pass a float "byref" to a method in objective C? Here's an overview of what I've got:

method signature:

- (void) MyMethod: (float*) min max:(float*) max;

method:

- (void) MyMethod: (float*) min max:(float*) max
{
}

trying to invoke it:

float min1 = 0; float max1 = 0; 
[self MyMethod: min:&min1 max:&max1];

I get the following warning, and the code abends when trying to invoke MyMethod:

warning: 'MyClass' may not respond to '+MyMethod:min:max:'

+3  A: 

The signature for your method is declared as

- (void) MyMethod: (float*) min max:(float*) max

but you are calling it as

- MyMethod:min:max:

... which includes an extra 'min:' that's not in the declaration.

Try changing your calling code to

float min1 = 0; float max1 = 0; 
[self MyMethod:&min1 max:&max1];

and see if that improves things.

However, I see that your error message complains about the signature '+ MyMethod:min:max:', which also suggests you're trying to send the message to the class rather than an instance of the class; you will have to rectify that.

Finally, method selectors in Objective-C code usually start with a lower-case letter; you might want to read up on common Objective-C naming conventions.

Christian Brunschen
Problem solved. The extra "min" thing was a typo when I was retyping the error message. The problem was actually (as you pointed out) that I was trying to invoke an instance method from a static/class method. I'll read up on the naming conventions. Thanks for the help!
Marty
Apple's naming conventions for their Cocoa framework(s) are described <a href="http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.html">here</a>.
Christian Brunschen
... or rather, here: http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.html
Christian Brunschen