• 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: Scope variable pattern
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Scope variable pattern (From: Yakov Zaytsev <email@hidden>)

  • Prev by Date: Re: Memory space in a shared, private framework
  • Next by Date: Re: [OT] iSnip
  • Previous by thread: Scope variable pattern
  • Next by thread: Re: Scope variable pattern
  • Index(es):
    • Date
    • Thread