Thread: non-static member initialization vs initializer lists

  1. #1
    Registered User
    Join Date
    May 2013
    Not so far

    non-static member initialization vs initializer lists

    I understand that if both are provided, the initializer list will take precedence, but what if I do not initalize all the member variables in the initializer list? Like for example,

    class Foo
    int myVar { 5 };
    const char *myStr { "String" };
    Foo() : myVar{} { } // What happens to Foo::myStr?
    In this case, myVar will be initialized to zero, but what about myStr? Will it remain uninitialized (and consequently have a garbage value)?

  2. #2
    Join Date
    Oct 2007
    Inside my computer
    It will be initialized to the default value specified in the class definition.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Static member initialization with class template
    By threahdead in forum C++ Programming
    Replies: 6
    Last Post: 04-28-2011, 12:16 AM
  2. Replies: 4
    Last Post: 08-29-2010, 04:33 PM
  3. Why initialization of static member is a must?
    By meili100 in forum C++ Programming
    Replies: 9
    Last Post: 04-11-2008, 05:22 PM
  4. non-const static member variale initialization
    By George2 in forum C++ Programming
    Replies: 29
    Last Post: 02-13-2008, 02:36 AM
  5. Derived member variables in initializer lists
    By bennyandthejets in forum C++ Programming
    Replies: 13
    Last Post: 11-27-2003, 04:30 AM

Tags for this Thread