We offer $20K to purchase apple enterprise account
As an iOS developer, I started learning C++ recently because developing audio players required some C++ knowledge.After reading 2 C++ books, I have some understanding of it. Here I share it with the students who need it. If there is something wrong with my writing, please point it out.Later, I will use the C++ knowledge I have learned to sign IOS app and write an article on FreeStreamer, the audio player, to analyze its implementation principle.This article focuses on the C++ syntax used by the FreeStreamer library.
In the development of IOS, C++ knowledge is occasionally used, but most students choose to escape every time they encounter this problem.Learning C++ syntax from scratch would take a lot of time, as I did, learning the basics.
Both Objective-C and C++ are designed based on the C language, and both have object-oriented capabilities.Before we sign IOS app and learn about C++, let's first learn about Objective-C++, which can be used in combination with C++ and Objective-C. Wouldn't it be better to use the best of both languages together?Tencent's open source database, WCDB, is a good example. It has not Classes are very important in object-oriented. In Objective-C, all classes must inherit from the NSObject Class. When you create a Class, it contains an.h and an.m file
In C++, creating a class also has a header file, person. HPP, and an implementation file, person. CPP In the implementation file, there is no @implementation Person @end in C++;
Every class in OC needs to inherit from NSObject;
C++ uses #include to import code from other files, while OC uses #import to import code from other files. Using #import ensures that no duplicate imports will be made in each file, while using #include requires the developer to sign IOS app and ensure that no duplicate imports will be made.
The Person class defines a public member variable, age, and a member function, isChild.A private member variable height and a member function isNomalHeight.In C++, you can define the scope of a variable or function. If it is used outside the scope, the compiler will report an error.In OC, we can call a function even if it is not defined in the.h file, so private functions starting with _ or a prefix are common in OC Memory is managed using reference count in OC, and when the reference count is 0, the memory space is freed.In C++, the developer manages the memory himself.To understand and sign IOS app C++ memory management, it is necessary to look at stack memory and heap memory. Stack memory: It allocates a fixed amount of memory. When a function executes, it allocates storage space for certain variables, and when the function completes, it frees its corresponding storage space.
Stackage is the stack memory. There is no need for the developer to sign IOS app and free the memory. The stackAge will be freed when the Agememory function completes.The heapAge is heap space. When the Agemory function completes, it will not be freed. It needs to be freed by the developer.
The following example creates a Person object that uses heap memory and requires a delete to free its memory.Note here that - > is used when accessing heap objects;To sign IOS app and access its members or methods, a stack object is accessed using.access its members or methods