# Include # import @ Class

Source: Internet
Author: User

# Include
Differentiate between # include <X. h> and # include "x. H"

# Include <X. h>: it is used to reference the system's built-in header file. The compiler searches for the file in the system file directory. .
# Include "x. H": a user-defined file is referenced in double quotation marks. The Compiler first searches in the user directory, then searches in the installation directory, and finally searches in the system file.


When using # include, pay attention to handling repeated references (this is also the difference between # include and # import in objc)

For example, if both classa and classb reference classc, classa is referenced in classd without repeated references. If classb is compiled, a duplicate reference error is prompted.

We can: # ifndef _ classc_h

# DEFINE _ classc_h

# Include "classc"

# Endif

In this way, there will be no repeated reference errors during compilation (in objc # import solves this problem, which is their difference)


# Import
# Most of the import functions are the same as those of # include, but it handles repeated references. We do not need to repeat the references when referencing files.

@ Class
declares a class and tells the compiler that its name is the name of a class, the definition implementation of this class is unknown for the time being and will be told later. it is also because only one class is declared in @ class, so the # import class is required in the subsequent implementation file. At this time, it contains all the information of the referenced class.


to sum up # include, # The difference between import and @ class can be understood as follows:


# include and # import When referencing a class, it will contain all information about the class, including the variable method, but this will affect the compilation efficiency. for example, if 100 classes # import classa, the 100 classes will process classa during compilation. for example, if a is referenced by B, B is referenced by C, and C is referenced by d ..... if a is modified, the following B, c, d ..... all need to be re-compiled. another method that may cause compilation errors is in classa # import classb in classb # import classa so during compilation Unknown errors may also occur.

So in general, when referencing a class in the interface, @ class is used. It will use this class as a type, and in the file implementing this interface, if you need to reference the object variables or methods of this class, you still need to import the class declared in @ class.

Original article: http://fei263.blog.163.com/blog/static/927937242012219103649197/

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.