initialization lists in header files?

This is a discussion on initialization lists in header files? within the C++ Programming forums, part of the General Programming Boards category; Where should I put initialization lists? In header files? cpp files? both? Thanks...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,170

    initialization lists in header files?

    Where should I put initialization lists?

    In header files? cpp files? both?

    Thanks

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,593
    This is related to "should I define member functions inline in the class definition?" and I think the answer is the same: it depends on the situation. If the constructor is going to do no work beyond initialising a few member variables, I tend to define the constructor inline, and thus I would have an initialisation list in the header. If not, I tend to define the constructor in a separate source file, in which case the initialisation list would be in the source file. However, you cannot do both simultaneously (i.e., the one definition rule).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,170
    Ah I see. Thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. #include header files or .cpp files?
    By DoctorX in forum C++ Programming
    Replies: 3
    Last Post: 12-23-2006, 11:21 AM
  3. Conflicting Header Files
    By X PaYnE X in forum Windows Programming
    Replies: 17
    Last Post: 01-08-2004, 10:28 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21