Summary of mixed use of C/C ++/obj-C ZZ

Source: Internet
Author: User
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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.