• 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: Mixing Cocoa and C++
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mixing Cocoa and C++


  • Subject: Re: Mixing Cocoa and C++
  • From: Chris Espinosa <email@hidden>
  • Date: Thu, 19 May 2005 08:34:47 -0700

On May 19, 2005, at 5:17 AM, Theodore H. Smith wrote:

C++ destructors are not called on C++ class in a ObjC class field, when the ObjC class is dealloced.


Any strategies for dealing with this?


I've thought of making one C++ class which contains all the C++ stuff, and just new/delete a pointer to that class from my ObjC init/delloc methods.



In gcc 4.0 (Xcode 2.0 and later), try setting the following in your OTHER_CFLAGS:

-fobjc-call-cxx-cdtors
For each Objective-C class, check if any of its instance variables is a C++ object with a non-trivial default constructor. If so, synthesize a special - (id) .cxx_construct instance method that will run non-trivial default constructors on any such instance variables, in order, and then return self. Similarly, check if any instance variable is a C++ object with a non-trivial destructor, and if so, synthesize a special - (void) .cxx_destruct method that will run all such default destructors, in reverse order.

The - (id) .cxx_construct and/or - (void) .cxx_destruct methods thusly generated will only operate on instance variables declared in the current Objective-C class, and not those inherited from superclasses. It is the responsibility of the Objective-C runtime to invoke all such methods in an object's inheritance hierarchy. The - (id) .cxx_construct methods will be invoked by the runtime immediately after a new object instance is allocated; the - (void) .cxx_destruct methods will be invoked immediately before the runtime deallocates an object instance.

As of this writing, only the NeXT runtime on Mac OS X 10.4 and later has support for invoking the - (id) .cxx_construct and - (void) .cxx_destruct methods. 

Chris
 _______________________________________________
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

References: 
 >Mixing Cocoa and C++ (From: "Theodore H. Smith" <email@hidden>)

  • Prev by Date: Re: XCode 2.0 build style selection
  • Next by Date: XCode 2.0 function definition popup not working
  • Previous by thread: Mixing Cocoa and C++
  • Next by thread: XCode 2.0 function definition popup not working
  • Index(es):
    • Date
    • Thread