Re: NewCommer -win32 to cocoa
Re: NewCommer -win32 to cocoa
- Subject: Re: NewCommer -win32 to cocoa
- From: Christopher Corbell <email@hidden>
- Date: Fri, 24 Oct 2003 02:12:05 -0700
On Friday, October 24, 2003, at 01:32 AM, Waseem Ashraf wrote:
Hi,
I started learning cocoa this week, as in our office we need to
rewrite our
win32 application for mac users.
I want to know how can I use my c++ classes, which uses a lot virtual
functions, in cocoa application. Secondly can I pass the objective c
class
inherited from view to my c++ classes as a parameter.
Have you got any other thoughts as i don't want to rewrite my c++
classes in
objective c.
Thanks for your help in advance.
Waseem
Muhammad Waseem Ashraf
Senior Software Engineer
Mobile: + 44 (0) 7788628629
[....]
It's very easy to mix Objective-C and C++. Just make your
files .mm files instead of .m files and you can include C++
headers and use C++ objects in your Objective-C class methods.
The .mm files can also define C++ class methods.
There are a few things to look out for, probably the most
important being the different exceptions architecture. An
Objective-C exception will not unwind the stack and invoke
destructors etc. the way a C++ exception will.
Objective-C class objects are always on the heap, i.e. they
are always pointers, so you can pass them to C++ class methods,
store them in STL containers, etc. Of course like any pointers,
they won't automatically be released if you clear the container.
You can't generally declare a C++ class directly as a member
of an Objective-C class, as it will not be constructed. But you
can make a pointer to a C++ class a member of an Objective-C
class and use new() to allocate the class in the Obj-C class
init method, and delete it in the dealloc method.
In your .cpp files you won't be able to call Objective-C methods.
Anyone have more tips? Perhaps there is something like an
Objective-C++ FAQ out there - if not we should probably start
one....
- Christopher
_______________________________________________
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.