What happens to uninitialized class members in c++? If I have to do this, what should I take care of?
#include <iostream>
using namespace std;
class Foo {
int attr1, attr2;
public:
Foo ();
Foo::Foo () { attr1 = 5; }
Foo myThing();
What happens to uninitialized class members in c++? If I have to do this, what should I take care of?
#include <iostream>
using namespace std;
class Foo {
int attr1, attr2;
public:
Foo ();
Foo::Foo () { attr1 = 5; }
Foo myThing();
They are default initialized, which in case of fundamental types like
int
means that it will have an indeterminate value.You should take care to never read an indeterminate value.