Objective-C??C++???????
???????????? ???????[ 2014/12/26 13:34:35 ] ????????C++ net
????Using C++ With Objective-C
?????????Objective-C???????????????????????????????????C++??Objective-C????????????Objective-C++?????????????????Objective-C??ó???????????е?C++???
????Objective-C??C++???????
?????? Objective-C++?У???????C++??????÷?????????Objective-C???÷??????????????????????????????????κε????á??? ?磬C++????????Objective-C???????????????????Objective-C?????????C++????????????????????????????????
???????Xcode?????????".mm"???????????????????????????Objective-C++?????
/* Hello.mm
* Compile with: g++ -x objective-c++ -framework Foundation Hello.mm -o hello
*/
#import <Foundation/Foundation.h>
class Hello {
private:
id greeting_text; // holds an NSString
public:
Hello() {
greeting_text = @"Hello?? world!";
}
Hello(const char* initial_greeting_text) {
greeting_text = [[NSString alloc] initWithUTF8String:initial_greeting_text];
}
void say_hello() {
printf("%s/n"?? [greeting_text UTF8String]);
}
};
@interface Greeting : NSObject {
@private
Hello *hello;
}
- (id)init;
- (void)dealloc;
- (void)sayGreeting;
- (void)sayGreeting:(Hello*)greeting;
@end
@implementation Greeting
- (id)init {
if (self = [super init]) {
hello = new Hello();
}
return self;
}
- (void)dealloc {
delete hello;
[super dealloc];
}
- (void)sayGreeting {
hello->say_hello();
}
- (void)sayGreeting:(Hello*)greeting {
greeting->say_hello();
}
@end
int main() {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
Greeting *greeting = [[Greeting alloc] init];
[greeting sayGreeting]; // > Hello?? world!
Hello *hello = new Hello("Bonjour?? monde!");
[greeting sayGreeting:hello]; // > Bonjour?? monde!
delete hello;
[greeting release];
[pool release];
return 0;
}
|
???????????????OC?????????C????????????????OC?????????C++????C???????OC????ж????C++????????Χ???????OC??????????????C?????????C++????????????????????Χ????μ????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11