- Reaction score
- 1,632
Code:
#include <iostream>
#include <cstdlib>
class A {
protected:
int a0;
public:
void a(){
std::cout << a0 << std::endl;
}
};
int main(){
A a = {};
a.a(); //If a0 is not initialized, { } will set the uninitialized a0 to its default value, 0.
//If a0 is initialized, { } will do nothing about it.
A b; //If a0 is not initialized, simply constructing the class object will set a0 to garbage value, such as:
//0xFFFF FFFF CCCC CCCC or -858,993,460.
//This value means undefined unsigned long integer value, or uninitialized memory data.
//If a0 is initialized, then after the class object is constructed, the class member, a0,
//will have that initialized value set as its default.
b.a();
system("pause");
return 0;
}