ATC :: Since February 2001

Subscribe to ATC Send e-mail to Rob

I work at Pelco. The opinions expressed here are my own, and neither Pelco nor any other party necessarily agrees with them.

View Rob Fahrni's profile on LinkedIn

Google
Web rob.crabapples.net



Krusty will code C++ for food.

Need a Snow Day?


RSS
Harry Potter Automatic News Aggregator
Green Hosting! This site is hosted by Dreamhost.

Sunday, April 20, 2008

Mixing Objective-C and C++ - [9:19 AM]

A couple of weeks back I linked to John Nack's discussion of the 64-bit port of Photoshop, it's not a trivial task, but I'd forgotten you can mix C++ and Objective-C. This will make it easier for the Adobe crew to port Photoshop, but it's still going to be one heckuva chore!

Here's a VERY simple example. The Objective-C file, main in this case, is using the C++ class named CPPClass. Please note I had to rename the main.m file to main.mm so the compiler would treat it properly. I've also heard you can name the file '.M', or find a specific compiler setting that'll do the same trick for you. I don't know what that setting is, sorry.

Anywho, here's the simple sample.

#import 
#import "cppclass.h"

int main(int argc, char *argv[])
{
CPPClass* c = new CPPClass();
c->Method1(99);
c->Method2("Rob was here");
delete c;

return NSApplicationMain(argc, (const char **) argv);
}

Labels: , , , ,


Click here for a permalink to this entry. comment