cEntity::cEntity (int x, int y, int height, int width) {
right
X,Y,Height,Width = new int;
not so much. This sets Width to the new int , but not all the others. You probably planned:
X = new int(x); Y = new int(y); Height = new int(height); Width = new int(width);
Please note that this construction method will not work for objects without assignment / copying, for example links. For some objects, it is also slower than creating them. Thus, the preferred way to build it looks like this:
cEntity::cEntity (int x, int y, int height, int width) { :X(new int(x)) ,Y(new int(y)) ,Height(new int(height)) ,Width(new int(width)) {}
This is better, but if any exceptions are thrown, you will have to somehow release the highlighted ones. It is better to make each of these members std::unique_ptr<int> , so that they free themselves and save you a lot of headaches.
source share