Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objective-C++: passing Objective-C objects to C++ methods?




On Nov 11, 2006, at 8:21 PM, <email@hidden> <email@hidden> wrote:


Unfortunately, I don't have a Mac available to test this with. What
behavior does Apple's version of GCC exhibit for the above
Objective-C++ code? Does it compile?

The following compiles just fine on Mac OS X (using "gcc version 4.0.1 (Apple Computer, Inc. build 5363)") and produces the following output.


100
200
100
200

==== Test.mm ====

#import <stdio.h>
#import <Foundation/Foundation.h>

@interface Test : NSObject {
	int i;
}
-(id) init:(int)n;
-(id) print;
@end

@implementation Test
-(id) init:(int)n {
	i = n;
	return self;
}

-(id) print {
	printf("%d\n", i);
	return self;
}
@end

class printer {
public:
    void print_Test(Test* test) {
		[test print];
    }
	
    void print_id(id test) {
		[test print];
    }
};

int main(int argc, char** argv) {
	
	Test* test_Test = [[Test alloc] init:100];
	id test_id = [[Test alloc] init:200];
	
	printer p;
	
	p.print_Test(test_Test);
	p.print_Test(test_id);
	
	p.print_id(test_Test);
	p.print_id(test_id);
	
	return 0;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Objective-C++: passing Objective-C objects to C++ methods? (From: <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.