What is the difference between #include
and #import
in C++?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
import was also one of the keywords associated with n2073, Modules in C++, proposed to the language committee by Daveed Vandevoorde in September 2006. I'm not enough of a language geek to know if that proposal was definitively shelved or if it's awaiting an implementation (proof of concept) from the author or someone else...
#import
is a Microsoft-specific thing, apparently for COM or .NET stuff only.#include
is a standard C/C++ preprocessor statement, used for including header (or occasionally other source code) files in your source code file.Please note that in gcc 4.1,
#import
is deprecated. If you use it, you will get warning:Import in VC++:
#import
is for type libraries or .tlbs (COM stuff).The content of the type library is converted into C++ classes, mostly describing the COM interfaces for you automatically, and then it is included into your file.
The
#import
directive was introduced by Microsoft as an extension to the C++ language. You can read about it at this MSDN article.The
#import
directive is also used with .NET / CLI stuff.Import in gcc: The import in gcc is different from the import in VC++. It is a simple way to include a header at most once only. (In VC++ and GCC you can do this via
#pragma
once as well)The
#import
directive was officially undeprecated by the gcc team in version 3.4 and works fine 99% of the time in all previous versions of gcc which supportInclude:
#include
is for mostly header files, but to prepend the content to your current file.#include
is part of the C++ standard. You can read about it at this MSDN article.#import
is overall a solution to the usualwork-around.
#import
includes a file only if it hasn't been included before.It might be worth noting that Apple's Objective-C also uses
#import
statements.