Note that there are some explanatory texts on larger screens.

plurals
  1. PO#pragma once and #include issues
    primarykey
    data
    text
    <p>I had an issue of circular references (i.e. A.h and B.h #including each other) and some people advised me to use #pragma once to prevent that. However, this solution appears to be not working still.</p> <p>What's happening is that class A no longer becomes recognized in any file other than A.h (not even in A.cpp) and the same happens for class B. </p> <p>Let me show you the code:</p> <p><strong>A.h</strong></p> <pre><code>#pragma once #include "B.h" class A { public: B* b; }; </code></pre> <p><strong>B.h</strong></p> <pre><code>#pragma once #include "A.h" class B { public: A* a; }; </code></pre> <p><strong>A.cpp</strong></p> <pre><code>#include "stdafx.h" #include "A.h" #include "B.h" </code></pre> <p><strong>B.cpp</strong> is same as <strong>A.cpp</strong></p> <p>The error trace reads as followed:</p> <blockquote> <p>1> B.cpp 1>c:\users\user\documents\visual studio 2010\projects\envmodel\test\b.h(5): error C2143: syntax error : missing ';' before '<em>' 1>c:\users\user\documents\visual studio 2010\projects\envmodel\test\b.h(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\user\documents\visual studio 2010\projects\envmodel\test\b.h(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1> A.cpp 1>c:\users\user\documents\visual studio 2010\projects\envmodel\test\b.h(5): error C2143: syntax error : missing ';' before '</em>' 1>c:\users\user\documents\visual studio 2010\projects\envmodel\test\b.h(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1>c:\users\user\documents\visual studio 2010\projects\envmodel\test\b.h(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int</p> </blockquote> <p>There are two more things I'd like to clarify:</p> <ol> <li><p>How and when to use #include "stdafx.h" in Visual Studio 2010 (I really hate this IDE, but it appears to be the only one that works well with C++ - Netbeans is total trash with this language)</p></li> <li><p>How to use #pragma once correctly? I'd assume I'd just put it at the first line of each file (well, obviously that doesn't solve my problems!). Also, should it be placed before or after #include "stdafx.h"? Note: I didn't put #pragma once in stdafx.h</p></li> </ol> <p>Thanks.</p> <p>Edit: I forgot the semi-colons, thus the original error trace was bloated. Edit2: I forgot to use pointers. My actual program did use pointers instead of plain object values and I neglected that in my haste to create a small example.</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.
 

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