C ++ overriding due to including header files multiple times
As the title says. I am facing override errors due to including header files multiple times. I know it because of this, but I don't know how to solve it. Yes, I previously posted the same issue on SO an hour in advance. But I couldn't explain correctly (I think so) and didn't get the expected answers. Here is the link:
I am not editing this question as it was filled in :).
Ok, I have several classes and their structure looks like this:
main.cpp:
#include "Server.h"
#include "Handler.h"
#include "Processor.h"
int main(int argc, char* argv[])
{
}
server.h:
// Server.h
#pragma once
#include <winsock2.h>
Handler.h:
// Handler.h
#pragma once
#include <string>
#include <vector>
#include "Server.h"
Processor.cpp:
// Processor.cpp
#include "StdAfx.h"
#include "Processor.h"
#include "Handler.h"
server.cpp:
// Server.cpp
#include "Server.h"
#include "Processor.h"
The problem is that it <winsock2.h>
turns on several times, I don't know where it is. # pragma does the same task once as
#ifndef SOME_FILE_H
#define SOME_FILE_H
// code here
#endif // SOME_FILE_H
in my compiler (MSVC2008 in this case). So I'm pretty sure I don't need a heading that includes guards. But can you determine where I am making the mistake that <winsock2.>
turns on twice and how can I solve?
thank
source to share
Have you tried any suggestions we made in your other answer?
Seriously try using include guard instead #pragma once
.
If you still have an issue, then maybe go back and post another question on SO. Don't post multiple questions about the same thing because you don't want (or can't) take our advice!
source to share