Re: Scope variable pattern
Re: Scope variable pattern
- Subject: Re: Scope variable pattern
- From: "Clark Cox" <email@hidden>
- Date: Fri, 11 May 2007 05:52:33 -0700
On 5/11/07, Yakov Zaytsev <email@hidden> wrote:
Hi,
I used this pattern for ages when I was exposed to C++ world, like
this obviously
struct ScopedDoing {
ScopedDoing () { /* doing.. */ }
~ScopedDoing () { /* clean up.. */ }
};
..
<some function body>
{ ScopedDoing aScopedDoing; ...
}
..
I wonder if it's possible to implement something similar with ObjC
Not in pure Obj-C code. However, if you use Obj-C++ (by renaming your
*.m files to *.mm), you can simply use your C++ classes directly.
e.g.
class MyAutoreleasePool
{
id m_pool;
public:
MyAutoreleasePool() : m_pool([[NSAutoreleasePool alloc] init]) {}
~MyAutoreleasePool() { [m_pool release]; m_pool = nil; }
};
{
MyAutoreleasePool localPool;
<body goes here>
return noErr;
}
--
Clark S. Cox III
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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