The line
World(height, width);
constructs a temporary object and discards it. The member variable of the current object never get initialized properly.
Simplify your code. Move the code to get input data to the function that calls it. For example, use it in main
.
int width = -1;
int height = -1;
cout << "Aby rozpoczac gre wpisz rozmiar planszy" << endl;
cout << "Aby uruchomic domyslne romiary zostaw pole puste" << endl;
cout << "Podaj szerokosc: ";
// I don't see what i'm typing and i need to press enter twice;
cin >> width;
cout << "Podaj wysokosc: ";
// I don't see what i'm typing too and make my program crash
cin >> height;
World w(height, width);
Simplify the default construtor (replace heightMember
and widthMember
with the real member variables):
World::World() : heightMember(0), widthMember(0) {}
solved C++