c++ - Dynamic array allocation during constructing object, invalid use of non-static variable -
c++ - Dynamic array allocation during constructing object, invalid use of non-static variable -
class array { public: array(unsigned h, unsigned l, std::initializer_list<double>); .... private: unsigned length; double * array; ... }; array::array(unsigned l, std::initializer_list<double> il) : length(l) { array(new (std::nothrow) array[l]); if (!array) throw outofmem(); (auto el = il.begin(), int = 0; < length; i++) { if (el === il.end()) throw wrongdim(); array[i] = *el; el++; } } }
it's justthe draft of original class have assignment. compiling results in error:
invalid utilize of non-static info fellow member 'length' unsigned length;
anyone got clue how prepare this?
what about:
int i=0; (auto &el : il) array[i++] = el; if (i!=l) throw wrongdim();
c++ arrays dynamic allocation
Comments
Post a Comment