The data elements of your class remain uninitialized because you explicitly asked the compiler to leave them uninitialized. You did this by writing a default constructor that does nothing to initialize them.
Entity::Entity(void) { }
If your class has not defined a custom constructor, then this syntax
Entity* entity = new Entity();
initiates the so-called initialization of the value of a new object, which would really set all immediate members of the scalar Entity
data to zero.
However, at the very moment you wrote your own default constructor, Entity::Entity()
, you basically told the compiler that you want to suppress the initialization of the initialization of the Entity
class and that you want to initialize such elements manually. So now you have to do it for sure: manually initialize all immediate scalar Entity
data items. Since you did not do this in your constructor, these members have remained uninitialized.
source share