• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Objective-C++: passing Objective-C objects to C++ methods?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: Re: Objective-C++: passing Objective-C objects to C++ methods?
  • From: Shawn Erickson <email@hidden>
  • Date: Sat, 11 Nov 2006 20:56:58 -0800


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:
This email sent to email@hidden


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

  • Prev by Date: Objective-C++: passing Objective-C objects to C++ methods?
  • Next by Date: Re: Objective-C++: passing Objective-C objects to C++ methods?
  • Previous by thread: Objective-C++: passing Objective-C objects to C++ methods?
  • Next by thread: Re: Objective-C++: passing Objective-C objects to C++ methods?
  • Index(es):
    • Date
    • Thread