Summary of mixed use of C/C ++/obj-C ZZ I also have some summary on my own, but I got it after I had been exploring it for a long time. Later I saw this article from netizens.ArticleIn the past, we can avoid detours. 1) when the obj-C compiler processes files with a suffix of m, it can recognize CodeTo process the MM file, you can identify obj-C, C, C ++ Code. However, the CPP file must only use C/C ++ code, and the include header file of the CPP file contains, the obj-C code cannot appear either, because CPP is only CPP.
2) Mix CPP in the MM file and use it directly. Therefore, obj-C Mixed CPP is not a problem.
3) Mixing obj-C in CPP is actually what we want to write modules using obj-C.
If the module is implemented as a class, write the class definition according to the CPP class standard. The header file cannot contain obj-C, including # import cocoa. In the implementation file, that is, the implementation code of the class can use obj-C and can be imported, but the suffix is mm.
If the module is implemented by functions, the header file should declare the function in the C format. In the implementation file, the C ++ function can use obj-C internally, but the suffix is still mm or M.
Summary: as long as the CPP file and the CPP include file do not contain obj-C, you can use it. The key to mixing CPP with obj-C is to use interfaces, instead, you cannot directly use the implementation code. In fact, CPP is a mix of the O files compiled by obj-C. This is actually the same, so it can be used. The combination of obj-C and CPP is simple. You can use it directly, because the obj-C compiler supports it.