Do I have to initialize simple class member variables?

Posted by Frank on Stack Overflow See other posts from Stack Overflow or by Frank
Published on 2010-06-16T12:09:24Z Indexed on 2010/06/16 12:12 UTC
Read the original article Hit count: 143

Filed under:
|
|
|

Quick beginner's question:

Do I have to initialize simple class member variables, or are they guaranteed to get assigned their default values in any case?

Example:

class Foo {
  int i;
  // is i==0 or do I need the following line for that?
  Foo() : i(0) {}
};

Thanks!

© Stack Overflow or respective owner

Related posts about c++

Related posts about class