Finally, leave in client.cpp the definitions of your class's member functions.Ĭlass SocketClient // Or whatever the name is.īool read(int, char*) // Or whatever the name is. Put the definition of your class in a separate client.hpp file which does not contain also the definitions of the member functions of that class then, let client.cpp and main.cpp include that file (I mean #include). This is one of the reasons why you do not usually #include. Therefore, all the symbols defined in the client.cpp translation unit will be defined also in the main.cpp translation unit. The reason is most certainly that main.cpp includes client.cpp, and both these files are individually processed by the compiler to produce two separate object files. The linker finds out that you have the same symbol defined multiple times in different translation units, and complains about it (it is a violation of the One Definition Rule). ![]() After compilation, the linker will merge the object files resulting from the compilation of each of your translation units (. This is not a compiler error: the error is coming from the linker. Take this fact into osideration before voting for duplicate, because this simply means beheading me without mercy. Asking for help, clarification, or responding to other answers. I have read this answer, but it was no help, since it expects double inclusions. Thanks for contributing an answer to Stack Overflow Please be sure to answer the question.Provide details and share your research But avoid. One interesting thing is, that when I remove #include from client.cpp, I get errors thouhg it is included in main.h too.Īs you can see, I'm not double defining/including my class, its included exactly once in main.h. ![]() ![]() Note it is complaining about my class, not boost. Main.obj : error LNK2005: "public: bool _thiscall SocketClient::read(int,char *)" already defined in client.obj This is what compiler is complaining about: This is structure of my project: main.cpp #include "main.h" I happened to get that already defined in.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |