I have conditional main.cpp:

#include "stdafx.h" using namespace std; int main(int argc, char *argv[]) { Classname classname(argc, argv); //body } 

Classname is described in Classname.cpp:

 #include "stdafx.h" using namespace std; class Classname{ public: Classname(int ArgumentsAmount, char *ArgumentsList[]) {} }; 

Also stdafx.h:

 //includes #include "Classname.cpp" 

The logic is: Classname I need to use in many classes (main as an example), Classname itself uses the functions of many libraries from stdafx.h, if everything is left as above, there will be an error at the compilation stage

 'Classname':'class' redefinition 

How can you realize maximum convenience so that you do not prescribe a code in each class that uses the functions from Classname

 #include "Classname.cpp" 

    1 answer 1

    You can add a file using include cpp. But this is not very expected. Correctly put your class in the h file and add #pragma once (or the classic header guard #ifndef #define #endif and add this h file to stdafx.h.

    If you add #include "Classname.cpp" in each file, this will not save you from the above error.

    • and such a question, if my code is all in hpp files, what it is, or what problems it can cause (on small projects everything is OK, big problems are of interest). - pavel
    • I still see only one significant problem - an increase in compile time. - KoVadim
    • and more) if the project is going to only with the flag [ignore multiple linking] then is this a problem in the project or is it normal? - pavel
    • I do not know of such a flag. But I suspect that you already have a problem in the code. She just had not yet manifested. - KoVadim
    • I meant /FORCE:MULTIPLE could be expressed incorrectly. - pavel