• 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
Blocks in C++ class vs. Obj-C class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Blocks in C++ class vs. Obj-C class


  • Subject: Blocks in C++ class vs. Obj-C class
  • From: Rick Mann <email@hidden>
  • Date: Sat, 12 Mar 2011 18:45:59 -0800

I've noticed a difference in the way local variables in blocks are handled in C++ classes vs. Objective-C classes. Take the following example, where all of this is compiled in a .mm file:

class Foo
{
    void foo();
};

void
Foo::foo()
{
    ^{
        int a = 1;  //  Error: 'int Foo::a' is not a static member of 'class Foo'
    };
}

@interface Bar

- (void)        bar;

@end

@implementation Bar

- (void)
bar
{
    ^{
        int a = 1;  //  no error
    };
}

@end

Why can I not assign to a locally-declared variable in a block that exists within a C++ method, but I can in an Objective-C method?

This is Xcode 3.2.5, gcc-4.2

Thanks,
Rick

 _______________________________________________
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

  • Follow-Ups:
    • Re: Blocks in C++ class vs. Obj-C class
      • From: Rich Siegel <email@hidden>
  • Prev by Date: Re: Xcode 4 Documentation
  • Next by Date: Re: Xcode 4 related questions
  • Previous by thread: Re: Xcode 4 Documentation
  • Next by thread: Re: Blocks in C++ class vs. Obj-C class
  • Index(es):
    • Date
    • Thread