This is objective-c code.
@interface Foo : NSObject { NSInteger _a; } @property (nonatomaic, assign) NSInteger a; @end @implement Foo @synthesize a = _a; @end
You know the phrase "@synthesize". @synthesize, create the following codes.
- (NSInteger)a { return _a; } - (void)setA:(NSInteger)aa { return _a = aa; }
Allow access property a.
void main() { Foo foo = [[Foo alloc] init]; foo.a = 1; }
Must assign foo.a as 1. But the compiler is invoked as below.
void main() { Foo foo = [[Foo alloc] init]; [foo setA:1]; }
foo.a = 1 and [foo setA: 1] is the same. foo.a = 1 calls [foo setA: 1].
Anther written in C.
class Foo { private: int _a; public: int getA(); void setA(const int aa); }; int Foo::getA() { return _a; } void Foo::setA(const int aa) { _a = aa; }
foo1.a and foo2-> a is 2. An example of Objective-C is below.
void main() { Foo *foo1 = [[Foo alloc] init]; foo1.a = 1; Foo *foo2 = foo1; foo2.a = 2; NSLog(@"result>>> %d, %d", foo1.a, foo2.a); } result>>> 2, 2
Have a nice day. Thanks.
source share