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,215

    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
    23,628
    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).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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,215
    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