Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

Possible Duplicate:
C++ include and import difference

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

like image 961
user659086 Avatar asked Mar 14 '11 15:03

user659086


People also ask

What is the meaning of difference between?

The difference between two things is the way in which they are unlike each other. That is the fundamental difference between the two societies. [ + between] There is no difference between the sexes.

What is difference between among and between?

The most common use for among is when something is in or with a group of a few, several, or many things. The most common use of between is when something is in the middle of two things or two groups of things. It is sometimes used in the phrase in between.

What is difference between different and difference?

Difference vs Different Different or difference is the quality or condition of being unlike or dissimilar. The only difference between these words is in its usage in English grammar. Difference is the noun, whereas different is an adjective.


2 Answers

  • #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 #.

like image 185
Didier Trosset Avatar answered Oct 05 '22 23:10

Didier Trosset


#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.

like image 43
Sylvain Defresne Avatar answered Oct 05 '22 22:10

Sylvain Defresne