• 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: why can't you initialize variable in case statements
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: why can't you initialize variable in case statements


  • Subject: Re: why can't you initialize variable in case statements
  • From: Tom Saxton <email@hidden>
  • Date: Wed, 21 Sep 2005 17:05:00 -0700

On 9/21/05, Scott Fraser <email@hidden> wrote:
> switch (someKey)
> {
>         case 1:
>                 {
>                         someClassPointer myClassPointer = new
> someClassPointer(anInitialValue);
>                         myClassPointer->doesSomething();
>                         break;
>                 }
>         case 2:
>                 {
>                         someOtherClass myOtherPointer = new someOtherClass(anInitialValue);
>                         myOtherPointer->doesSomethingElse();
>                         break;
>                 }
> }
>
> Now, each class instance goes out of scope (and its destructor is
> called) as it leaves the "case", rather than the "switch".

Actually, that's not correct. Destructors don't get called on object
pointers (created with "new") when they go out of scope. Objects yes,
pointers to objects no.
 _______________________________________________
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: 
 >Re: why can't you initialize variable in case statements (From: Scott Fraser <email@hidden>)

  • Prev by Date: Re: NSObjCRuntime.h won't compile? Or .mm files?
  • Next by Date: Re: Specifying Where The Build Product Should Be Placed
  • Previous by thread: Re: why can't you initialize variable in case statements
  • Next by thread: Specifying Where The Build Product Should Be Placed
  • Index(es):
    • Date
    • Thread