why we import header file in the other file.
Asked
Active
Viewed 111 times
0
-
May be answer to this post also answers your question: http://stackoverflow.com/questions/322597/class-vs-import. – Mudassir Feb 28 '11 at 10:25
2 Answers
0
Its just another name, rather than #include
If you do not import the header file then the compiler doesn't know where some of the things you use in your code come from. Its like importing a dictionary when you are writing in a foreign language, without the dictionary you don't know what everything means or does.

Antwan van Houdt
- 6,989
- 1
- 29
- 52
-
Just to expand a little on Antwan's answer, `#import` and `#include` both do a very similar job, with the difference being that `#import` makes sure that the imported file is only imported once, but `#include` will include the contents of a file twice if you `#include` it twice. – Mac Feb 28 '11 at 10:36
-
@Mac didn't know that, thats pretty cool. Kinda explains why I never got any errors after the 900th call to #import
– Antwan van Houdt Feb 28 '11 at 10:40 -
that's pretty much exactly it :) Saves the hassle of include guards like you find plastered throughout typical C/C++ code. – Mac Feb 28 '11 at 10:49
0
In general "importing" (including) source files/header files is meant to let the current file "see" the objects defined in the imported one.

Manrico Corazzi
- 11,299
- 10
- 48
- 62