-------<a href= "http://www.itheima.com" target= "blank" >android training </a> <a href= "/http/ Www.itheima.com "target=" blank ">java training </a>, look forward to communicating with you! ----------
dot Syntax1. Point syntax related to setter and getter
Person *p = [person new];
[P setage:10]; Equivalent to P.age = 10;
int a = [P age]; equivalent to int a = P.age;
2. Description:
P.age = 10; The member variable _age of the P object is not accessed, and even the member variable _age that accesses the P object should be written as P--_age; the correct meaning of this sentence is to invoke the Setage: method of the P object.
3.p.age = 10; the difference from p.age:
If there is an assignment, that is: P.age = 10, that is, the setage of the P object is called : method; no assignment, i.e. p.age; Represents the Getage method that called the P object:(int) age;
The only way to access member variables directly in 4.OC is with the arrow -, the point syntax does not represent the member variables of the direct Access object; 5. Analysis of the real function of point grammar
- In fact, the point syntax is the invocation of the method ;
- When the point syntax is used, the compiler automatically expands to the appropriate method ;
6. Use of Point syntax note that improper use of dot syntax can cause a dead loop:
The Dark Horse program----OC dot syntax