OBJECTIVE-C member variables

Source: Internet
Author: User

Access permissions for member variables

The member variables in OBJECTIVE-C have the following three properties

    • Public (external and sub-class accessible)
    • Protected (sub-class accessible, externally inaccessible)
    • Private (external and sub-class inaccessible)

By default, the protected property

Example: Class A has 3 properties, Class B is a subclass of Class A, and the main function is external to class A.

A.h

@interface a:nsobject{@public    int Publicvar; @protected    int Protectedvar; @private    int Privatevar;} @end

Main.m

int Main (intconstChar * argv[]) {    @autoreleasepool    {        *a = [[A alloc] init];        A1;       // OK        2;    // Error Compilation But        3;      // Error Compilation But     }    return0;}

B.m

@implementation B-(void) f{    *b = [[[B alloc] init];    b1;       // OK    2;    // OK    3;      // Error Compilation But }@end

Note that the way you visit here is "--" instead of "." Oh oh oh oh

OBJECTIVE-C member variables

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.