开发者

What is the difference between #import and #include in C++? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

C++ includ开发者_开发技巧e and import difference

Can someone explain the difference and where may I use one versus the other?


  • #include includes a file in the current compilation unit.
  • #import does not exist in the C++ standard.

This answer was true in '14. However, the C++ standard has evolved since then and import now exists. Without the #.


#include cause the referenced file to be "copy-and-pasted" at the current position during the preprocessing phase.

#import is not in the C++ standard, but is an extension provided by some compiler. There is no consensus about what it does. For GCC, it is equivalent to #include but try to ensure that the file has not already been included. For MSVC, it may have another meaning.

It is best to avoid #import (sadly) if you want to write code portable to multiple compilers.


  • #import imports information (types, functions, variables etc) from .lib file. It's non-standard directive.
  • #include includes header file.

See these topics:

  • #import Directive (C/C++)
  • #include Directive (C/C++)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜