main.cpp

#include "server.h" void main() { } 

packet.h

 #pragma once #ifndef _PACKET_H #define _PACKET_H .. #endif 

server.h

 #pragma once #ifndef _SERVER_H #define _SERVER_H #include "packet.h" .. #endif 

List of errors:

LNK2005 error "public: virtual void __thiscall IncomingAuth :: handler (class Parcer &)" (? Handler @ IncomingAuth @@ UAEXAAVParcer @@@ Z) is already defined in main.obj EmulatorTop C: \ Users \ Ilya \ Documents \ Visual Studio 2015 \ Projects \ EmulatorTop \ ThreadEvents \ server.obj

If you change the main, then compiled.

main.cpp

 #include "packet.h" void main() { } 
  • one
    In server.h, you have not only declared something, but also defined it , so as a result, when you compile both server.cpp and main.cpp, you get two entities with the same name, which is very frustrating to the linker ... - Harry
  • one
    And yet - this is not a compilation error, but LINKS. - Harry
  • It turns out that classes and methods were defined in packet.h. I brought the methods to .cpp and it all worked. - Tarakan
  • one
    Well, I'm not surprised :) - Harry

1 answer 1

The compiler issues error messages specifically for you to read. This error message, issued when linking compilation units, is very clear: the handler function is defined in two compilation units.

Most likely, it is defined in the server.h header file and is not embedded, that is, it does not have an inline function specifier.

Either remove the function definition from the header, or declare it with the inline specifier.

Keep in mind that although the MS VC ++ compiler compiles a main function declaration such as

 void main() 

it does not comply with the C ++ standard. According to the standard, the main function without parameters should be declared as

 int main()