Re: Synthesized ivar for std::tr1::shared_ptr<MyClass>?
Re: Synthesized ivar for std::tr1::shared_ptr<MyClass>?
- Subject: Re: Synthesized ivar for std::tr1::shared_ptr<MyClass>?
- From: Uli Kusterer <email@hidden>
- Date: Thu, 6 May 2010 12:30:00 +0200
On May 6, 2010, at 8:19 AM, Barry Wark wrote:
> Thus, I'm lead to believe this is an issue with runtime synthesizing
> of the ivar, but I'm at a loss to explain why it should be so. I would
> like to keep the C++ out of the header file if possible so that I can
> use standard Objective-C when importing the header file in client
> modules.
I don't have a solution. My guess is this is simply an ObjC++ compiler bug.
However, I can offer a workaround: Put your ivars in a struct, put a pointer to the forward-declared struct in your header as the sole ivar. In your implementation file, define the struct and use the 'new' operator in the init method to allocate the contents of the struct (which will also call all constructors). In the dealloc method, delete the struct (and set the ivar to zero for safety).
It's a little bit of added manual memory management, but from then on you can just add C++ ivars to the struct, as you'd do with the class. Just beware that you have to initialize all ivars, as you are not guaranteed to get zeroed-out memory back from C++ new (unlike ObjC's alloc).
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden