I have a sample class named class Player
. With constructor the program runs successfully without initialization. However, without constructor it generates an error uninitialized local variable e used
and you need to initialize it to a value say 0
. I want to know why the program behaving like this and how the compiler read this one?
class Player {
public:
float x, y; //this will not work without constructor or not being initialized
//float x = 0, y = 0; -> works successfully without constructor
A(){}
};
int main() {
Player e;
std::cout << e.x << e.y << std::endl;
return 0;
}