Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ redefinition due to including header files multiple times
    primarykey
    data
    text
    <p>As, the title says. I'm encountering redefinition errors due to including header files multiple times. I know its because of that, but I don't know how to resolve. Yes, I previously posted the same problem in SO an hour ahead. But I wasn't able to explain properly (I think so) and didn't get answers expected. Here is the link:</p> <p><a href="https://stackoverflow.com/questions/1372480/c-redefinition-header-files">C++ Redefinition Header Files</a></p> <p>I'm not editing that question since it has been filled up :).</p> <p>Okay I have some classes and the structure of them is like this:</p> <p><strong>main.cpp:</strong></p> <pre><code>#include "Server.h" #include "Handler.h" #include "Processor.h" int main(int argc, char* argv[]) { } </code></pre> <p><strong>Server.h:</strong></p> <pre><code>// Server.h #pragma once #include &lt;winsock2.h&gt; </code></pre> <p><strong>Handler.h:</strong></p> <pre><code>// Handler.h #pragma once #include &lt;string&gt; #include &lt;vector&gt; #include "Server.h" </code></pre> <p><strong>Processor.cpp:</strong></p> <pre><code>// Processor.cpp #include "StdAfx.h" #include "Processor.h" #include "Handler.h" </code></pre> <p><strong>Server.cpp:</strong></p> <pre><code>// Server.cpp #include "Server.h" #include "Processor.h" </code></pre> <p>The problem is that <code>&lt;winsock2.h&gt;</code> is included multiple times, don't know where but it is. <strong>#pragma once</strong> serves the same purpose as</p> <pre><code>#ifndef SOME_FILE_H #define SOME_FILE_H // code here #endif // SOME_FILE_H </code></pre> <p>in my compiler (MSVC2008 in this case). So I'm pretty much sure I don't need the header include guards. But can you spot where I'm doing the mistake by which <code>&lt;winsock2.&gt;</code> is included twice and how may I resolve?</p> <p>Thanks</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.
 

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