Re: Simple C++ variable initialization question

From: Jeff Schwab (jeffplus_at_comcast.net)
Date: 05/14/04


Date: Thu, 13 May 2004 18:10:30 -0400

Brendan wrote:
> For some reason, the most simple questin alludes me today... Perhaps
> you can shed some light for me.
>
> Say you have a class with a data member of type int or char or some
> primitive type.
>
> Very simple example, leaving out constructors, etc.
>
> class TestApp {
> public:
> int public_x;
> private:
> int private_y;
> char test_char = 'o';
> int test_int = 0;

That's illegal, unless test_char and test_int are static.

> }
>
> Do they all get defined to some initializer without being specifically
> stated, ie. public_x = 0;

It depends, but in general, the answer is no.

> Can I expect public_x to be 0 when I instantiate the class (just like
> test_int)?

No.



Relevant Pages

  • Re: Cracking DES with C++ is faster than Java?
    ... This is because 'x' is of type int in C but ... The reason is that in C, the comma operator returns and r-value, but in C++, it ... struct at the function scope thereby hiding the array. ...
    (comp.lang.java)
  • Re: Cracking DES with C++ is faster than Java?
    ... This is because 'x' is of type int in C but ... The reason is that in C, the comma operator returns and r-value, but in C++, it ... struct at the function scope thereby hiding the array. ...
    (comp.lang.cpp)
  • Re: Cracking DES with C++ is faster than Java?
    ... This is because 'x' is of type int in C but ... The reason is that in C, the comma operator returns and r-value, but in C++, it ... struct at the function scope thereby hiding the array. ...
    (sci.crypt)
  • Re: Is it a bad idea to introduce "Reference" in C++ ?
    ... Anyone can give a reason as to why it is NECESSARY? ... lvalue of type int, according to C++ standard 5.2.1 (not an int& as you ... references are not necessary in order to reason about the constructs you ... With sufficient thrust, pigs fly just fine. ...
    (microsoft.public.vc.language)