Thread: When to use a .cpp file

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    It is usually a good idea to put implementations in a separate file. However, it is reasonable to have the small functions inlined, therefore they need to be in the header anyway.

    Note that inlining large functions usually reduces performance (as far as I've seen).

    Compilers also mostly don't support putting templated code in a separate cpp file.

    Edit: One more thing. You can put the code that needs to be in the header (for inlining or templates) in a separate file and include that at the end of the header file. That's for organizational purposes only: the preprocessor will just paste that file into the header. It may also have a different extension, for example "*.tpp" for template code implementations.
    Last edited by anon; 07-25-2007 at 05:13 AM.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  3. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  4. Hmm....help me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM