CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2007
    Posts
    76

    Splitting up code?

    I was wondering, is it possible to split up your code into seperate files, like cpp files, that contained the functions? If so, would you have to "include" them or would they just be linked in?

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Splitting up code?

    Yes. Typically, you would place class definitions and function prototypes into headers, then implement the classes and functions in source files. You would include the relevant headers in the respective source files.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Dec 2007
    Posts
    76

    Re: Splitting up code?

    ok, alright, thanks.

  4. #4
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Splitting up code?

    To take LaserLight's statements a bit further.

    Typically there is one header (.h/.hpp) and one implementation (.cpp) per class.

    However for large classes it is also possible to divide the functions among multiple .cpp files so they are easier to track (or for other reasons like some of the functions being created by a code generator.

    It is generally a bad idea (and difficult) to split a header into multiple files, although it is physically possible via includes in the middle of the class definition.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured