c++ - Creating an array2D class crashing when compiling -
----------------------
repeated question
in these lines
array2d(int xres, int yres){ float **xtable;
you declaring local variable. class member variable of same name remains uninitialized , use later.
remove second line.
also, member variables xres
, yres
not initialized either.
use:
array2d(int xresin, int yresin) : xres(xresin), yres(yresin) { xtable = new float*[yres]; for(int i=0;i < yres;i++) { xtable[i] = new float[xres]; } }
also, change
void getsize(int &xres, int &yres){}
to
void getsize(int &xresout, int &yresout) { xresout = this->xres; yresout = this->yres; }
as expand class, keep in mind the rule of three , implement copy constructor , copy assignment operator.
array2d(array2d const& copy) { ... } array2d& operator=(array2d const& rhs) { ... }
Comments
Post a Comment