Re: Mixing Objective C and C++
Re: Mixing Objective C and C++
- Subject: Re: Mixing Objective C and C++
- From: Todd Heberlein <email@hidden>
- Date: Tue, 15 Oct 2002 13:44:14 -0700
On Monday, October 14, 2002, at 11:17 AM, Craig Bakalian wrote:
I have read the Using C++ with Object-C in the Cocoa Documentation,
however I am still confused about how to implement such a combination.
Is there an example out there somewhere?
I actually prefer C++ STL containers over the Foundation containers. I
know, call me weird... I also still like vi.
A couple of points I have found with Obj-C++:
1) Rename any source code file that has C++ code to a .mm file. I
rename the files from within Project Builder (e.g., right-click or
control-click the file name for the pull down menu, then select rename).
2) If I include C++ objects in an Obj-C object, I usually prefer to
declare the object as a pointer and then allocate the C++ object in the
"init" method.
3) If an object is pure Objective C, but it imports a header file that
uses C++ references, you still need to rename the implementation file
to a .mm file.
Anyways, below is a link to a relatively simple program I use to
generate test data for machine learning programs. Basically you select
an event type (circle, square, or triangle) and click on the view to
place the point there. You can save the data file as a .txt file
(e.g., to run through your supervised learning algorithm), or you can
save an image of the view as a PNG file.
The point is, however, that I have a simple C++ object representing an
event (X location, Y location, and event type), and I keep them in a
C++ STL vector container. I even use regular C fprintf for printing to
a file, so I have managed to mix several C dialects into one simple
program.
If you want to take a look at the program, you can find it on my iTools
account at:
http://homepage.mac.com/todd_heberlein/Development/FileSharing6.html
It comes as a compressed tar file. (I think iTools appends a funny
dlink label to the end of the file). If you would prefer a disk image,
let me know.
Todd
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.