Re: C++ in a Cocoa App - How Hard is THAT?
Re: C++ in a Cocoa App - How Hard is THAT?
- Subject: Re: C++ in a Cocoa App - How Hard is THAT?
- From: Rush Manbert <email@hidden>
- Date: Fri, 07 Oct 2005 18:19:35 -0700
Lance Drake wrote:
Hi XCode folks,
In an effort to write a snazzy little app which accesses a C++
object that came from a CodeWarrior Carbon project, I wrote a little
Cocoa app in which I would like to include that source file written in
C++. Evidently, it's lots easier to include Cocoa in Carbon... but I
digress.
As it happens, I cannot include the ".h" file in the Cocoa .m file
(so as to be able to create the object and then refer to it) as the
complaints appear immediately upon the compiler encountering the word
'class'.
Pouring thru the ADC refs, etc I found the instruction to set
'Other C Flags' to include '-ObjC++'. The file itself compiles. It's
the reference to it that seemingly cannnot be added into the Cocoa world.
Lance,
I have a Cocoa app that interfaces to a C++ library, and I have a class
on the Objective C side that derives from a class defined on the C++
side. As far as I can remember, all I had to do was to change the build
settings. Go to the Info window for your target, make sure you're
editing the proper configuration (sounds like it would be "all" for
you), and select the compiler Language collection. Set "Compile Sources
As" to Objective-C++ and you should be okay.
In my case, the C++ class is defined in foo.hpp. The C++ class on the
objective C side is defined in bar.h, and bar.h looks like this:
#include "foo.hpp"
class fooDerived : public foo
{
// Normal C++ class stuff
};
My implementation file is called bar.m, and it has no problems with
fooDerived objects. I'm only using them inside bar.m, but I just tried
adding one to one of my other Objective-C modules that imports bar.h and
it had no trouble either.
Good luck,
Rush
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden