Question on code from tutorial

The code on page 90 of the tutorial (the pdf version) has contained in the constructor the two lines

width = new int;
height = new int;

I don't understand what this is and why it is needed. Don't think "new" was talked about yet in the tutorial. Thanks.

Last edited on
Page 74.
oh that is right, "new" is for dynamic memory, thanks.
closed account (S6k9GNh0)
new simply allocates enough memory for sizeof(int);

Because there is no sequence in where the memory is located, it passes back a handle to the randomly allocated memory. You can then access your data by using the dereference(*). This is effecient for almost all large classes, large arrays, and almost everything placed inside of a buffer (audio decoding, mesh loading, useful for games).
Topic archived. No new replies allowed.