Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Move some functions to a new cpp file [modified]

Move some functions to a new cpp file [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Johpoke
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • J Johpoke

      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

      J Offline
      J Offline
      JudyL_MD
      wrote on last edited by
      #2

      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

      J 1 Reply Last reply
      0
      • J JudyL_MD

        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

        J Offline
        J Offline
        Johpoke
        wrote on last edited by
        #3

        Thanks! Works perfectly now :D

        //Johannes

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups