Definitions of OC objects and anonymous object objects and anonymous objects:
When new is an object, the pointer is usually called an object if it is received with a pointer.
If the new object is not received by the pointer, then the object is called an anonymous object.
#import<Foundation/Foundation.h>#import "Iphone.h"#import "Person.h"intMainintargcConst Char*argv[]) { //1. Accessing objects through pointersiphone *ip = [iphoneNew];//create an object and receive it using the pointer IP ip->_size = 4.3; This is a special notation for pointer access to struct member variables. OC objects are pointers that store a memory address in the heap. Ip.weight=Ten;//accessing the member variables of an object through point syntax[IP PowerOff];//methods for accessing objects through pointers//2. Anonymous objects, no pointers[IphoneNew];//An object is created here, but the object is not received with a pointer, which is an anonymous objectNote: Each time an anonymous object is created, the object is assigned a different storage space, meaning that each anonymous object is not the same. //3. No two identical anonymous objects[IphoneNew]->_CPU =5;//assigns a value to the 1th anonymous object _cpu[IphoneNew]->_size =4.0;//assigns a value to the 2nd anonymous object _size[IphoneNew]->_weight = the;//assigns a value to the 3rd anonymous object _weight[[IphoneNew] POWEROFF];//Call the 4th anonymous object Poweroff methodNSLog (@"%@", [IphoneNew]);//Print a 5th anonymous object//guess what, the results are all 0 printed here. //The reason is that each time an assignment is made, a new anonymous object is created, and nslog prints a new anonymous object whose member variables are not assigned a value. So it's all 0. //4. An anonymous object can be passed as an argumentPerson *p = [personNew]; Iphone*ip = [IphoneNew]; [P SENDSIGNAL:IP]; //here is passed by pointer, as argument[P Sendsignal:[iphoneNew]];//This is done using an anonymous object as an argument pass, but the [Iphone new] object is destroyed after this use, unless a new pointer references it. return 0;}
OC Objects and anonymous objects