Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Remember that the <code>#include</code> directive indicates to the preprocessor the contents of the specified file should be treated as if they appeared directly in the source file in place of the directive (paraphrased from <a href="http://msdn.microsoft.com/en-us/library/36k2cdd4(v=vs.71).aspx" rel="nofollow noreferrer">MSDN</a>).</p> <p>With that in mind, it seems like you are encountering improper order of <code>#include</code>s and also missing <code>#include</code>s. My guess would be that you are not including your own header file in your .cpp files. This would explain cases one and three. Consider the following files:</p> <pre><code>// header.h // #include &lt;linux/videodev2.h&gt; &lt;-- Option 1 class A { void func(uint32_t var); }; // header.cpp void A::func(uint32_t var) { // implementation } // main.cpp // #include &lt;linux/videodev2.h&gt; &lt;-- Option 2 #include "header.h" // #include &lt;linux/videodev2.h&gt; &lt;-- Option 3 int main() { // implementation; something creates an instance of A and calls func } </code></pre> <p>Now, Option 1 is <a href="https://stackoverflow.com/questions/2596449/including-includes-in-header-file-vs-source-file">not exactly desirable</a>; it's good practice to avoid <code>#include</code>s in header files because they can increase build times and create unwanted dependencies. However, it will ensure that the types <code>header.h</code> requires are there for it to use. The essential bit is that <strong>the contents of <code>linux/videodev2.h</code> have to appear before the contents of <code>header.h</code>, anywhere that <code>header.h</code> is <code>#include</code>d.</strong></p> <p>This brings me to Option 2. Option 2 will also compile correctly, because <code>linux/videodev2.h</code> is included before your header, and your header relies on types defined in it. Also important is that both <code>main.cpp</code> and <code>header.cpp</code> must <code>#include "header.h"</code>, because they reference symbols declared in it.</p> <p>If you were to go with Option 3, you would get compilation errors that the type <code>uint32_t</code> is not defined, and the compiler would point to your header file. This is because the contents of the header file appear before the contents of <code>linux/videodev2.h</code>, and so the compiler does not yet understand what the type <code>uint32_t</code> is when it encounters it.</p> <p>So, given all that, you have choices: include `linux/videodev2.h' before each include of your own header file, or include it directly in your header file. I mentioned earlier that the latter is not good practice, but for your particular case, it might be the better option of the two, in case your header file needs to be included in many .cpps.</p> <p>I think this would be a good opportunity to dive into <a href="http://en.wikipedia.org/wiki/Precompiled_header" rel="nofollow noreferrer">precompiled headers</a>, but I'm not as well-versed in them, so I'd leave it to someone who has more experience to explain them.</p> <p>Hope this helps :) </p>
    singulars
    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.
    2. VO
      singulars
      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