The function NSStringFromPoint disappears when I compile my code using objective-C++, but it's fine under objective-C.
开发者_开发知识库How can I make objective-C++ see that function?
If I compile under Objective-C++ it says:
error: 'NSStringFromPoint' was not declared in this scope
error: 'NSStringFromRect' was not declared in this scope
error: 'NSEqualSizes' was not declared in this scope
Someone can correct me if I'm wrong, but if you're linking against the iPhone SDK, there is no NSPoint
or NSStringFromPoint
. UIKit uses the Core Graphics structs CGPoint
, CGSize
and CGRect
. The equivalent function would be NSStringFromCGPoint
.
The Simulator libraries do not quite match up with the iPhone libraries -- I'm fairly certain applications compiled for the simulator link against the Mac's own Foundation.framework. For example, I wasted a lot of time in the pre-2.0 days thinking that NSXMLDocument
was available on iPhone because it compiled and ran in the simulator.
I compiled this simple application:
#include <Cocoa/Cocoa.h>
int main (void)
{
NSLog (@"%@", NSStringFromPoint(NSMakePoint(10, 10));
return 0;
}
Using this command line:
gcc -x objective-c++ test.mm -framework Cocoa -lstdc++
And I got this output (ignoring the error about no autorelease pool in place):
2010-05-12 12:41:33.946 a.out[290:10b] {10, 10}
Make sure you're including the right headers, at the very least, make sure you're importing <Foundation/Foundation.h>
. An explicit #import <Foundation/Foundation.h>
will do no harm if it has already been included.
精彩评论