Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>a primer on #include vs #import</h2> <p>importing (or including) a file is akin to injecting the contents of that file at the location of the #import statement. </p> <h3>Interesting details:</h3> <p>In Objective-C #import is smarter than the normal C #include in that if a file is already previously injected in an embedded #import chain, then it won't be injected again. the normal C (preprocessor) #include is not smart enough to figure that out which is why you always see constructs like</p> <pre><code> #ifndef __FOO_H #define __FOO_H .... header content here ... #endif /*__FOO_H */ </code></pre> <p>In C headers to ensure singular inclusions, whereas you don't see such constructs in objective C.</p> <p>That is all what <code>#import</code> is: a content injection mechanism.</p> <p>So, taking your own example, let's say I wanted to create an instance of the Person class, I would have to #import its definition before I could do that. :</p> <pre><code> /* main.m */ #import "Person.h" int main(int argc, char *argv[]) { Person *person = [[Person alloc] init]; //^^^^^^^^ this won't work without the #import statement [person release]; return 0; } </code></pre> <p>note that nothing is being inherited, #import just injects all the pieces needed to use the <code>Person</code> class in our main.m</p> <h1>a primer on inheritance</h1> <p>Inheritance is, as you probably already know, a mechanism to define a new class as an extension of another class. Typically, the new class is a subclass of the parent class (think animal kingdom), but not always. </p> <p>In your own example you define Employee as a sub-class of a Person.</p> <h2>So how does inheritance relate to #import?</h2> <p>Well in order to use a class for <em>anything</em> you need to #import its definition so that the compiler knows what you are talking about when you say <code>Person</code>, and that includes (pun intended) creating a derived class.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload