I accidentally applied for an iPhone development role some time ago. I was asked about the similarities and differences between objc and C ++. I always expressed my preference for C ++. I wrote a bit in two languagesCodeI think I can write some text for a simple comparison.
The first is memory management:
The C ++ version reaches C ++ 11 and does not support language-level GC. It happens that objc has never been willing to support GC on iOS devices.
C ++ is harmonious without GC, because the C ++ object is designed for static memory allocation.
The constructor of C ++ cannot be inherited. It is bound to the object during compilation, but does not have polymorphism at runtime. Therefore, you can know the object size exactly during the compilation period and allocate objects in the stack area.
While objc always binds objects and methods at runtime through the message mechanism. The polymorphism is really good. Through [self class], static methods of classes, such as allloc, are also Runtime polymorphism, therefore, it seems that only objects can be allocated in the heap area.
Alas, I was writing this article to write a better look, earn some clicks, And Then PS job information. The result is half of the phone number, and I finally have a job that suits me, so I am too lazy to write it down. That's all. Sorry.