Move some functions to a new cpp file [modified]
-
I wanted to move some things around, so i moved two functions from my dialog based MFC program (compiler= VC6.0) into a new cpp file called Functions.cpp I added the functions, and the #include "stdafx.h" to the new cpp file And added #include "Functions.cpp" into my "stdafx.h" file. But now when i attemp to compile i get errors like this for both functions: error C2084: function 'void __cdecl Func1(void)' already has a body I looked around, tried some ; on the function definitions, tried some #ifdef things but nothing seemed to work... So what do I do? thanks a million! :)
//Johannes
-
I wanted to move some things around, so i moved two functions from my dialog based MFC program (compiler= VC6.0) into a new cpp file called Functions.cpp I added the functions, and the #include "stdafx.h" to the new cpp file And added #include "Functions.cpp" into my "stdafx.h" file. But now when i attemp to compile i get errors like this for both functions: error C2084: function 'void __cdecl Func1(void)' already has a body I looked around, tried some ; on the function definitions, tried some #ifdef things but nothing seemed to work... So what do I do? thanks a million! :)
//Johannes
Johpoke wrote:
I added the functions, and the #include "stdafx.h" to the new cpp file And added #include "Functions.cpp" into my "stdafx.h" file.
You need to create a Function.h file that contains the prototypes for the functions now contained in Functions.cpp and include the .h, not the .cpp, in the stdafx.h file. Add the Functions.cpp file to the project. You're getting the "function already has body" because stdafx.h contains the contents of Functions.cpp - you told it to include it, so it did - and now you're trying to define the function again in the body of Functions.cpp. Judy
-
Johpoke wrote:
I added the functions, and the #include "stdafx.h" to the new cpp file And added #include "Functions.cpp" into my "stdafx.h" file.
You need to create a Function.h file that contains the prototypes for the functions now contained in Functions.cpp and include the .h, not the .cpp, in the stdafx.h file. Add the Functions.cpp file to the project. You're getting the "function already has body" because stdafx.h contains the contents of Functions.cpp - you told it to include it, so it did - and now you're trying to define the function again in the body of Functions.cpp. Judy