How to assign pointer of an "array of object" (C++) -
i beginner in c++ confused on dynamic array. found way in site, can't seem make work "array of object" in object. break when read rec variable.
this class definition:
class alcxio { private: alcx_io_record* rec[1]; int _count; public: int count(); void init(cl_displaywindow window); void addinput(int io_id); alcx_io_record* getrec(int recid); void on_input_down(const cl_inputevent &key, const cl_inputstate &state); void on_input_up(const cl_inputevent &key, const cl_inputstate &state); };
the addinput() function:
void alcxio::addinput(int io_id) { size_t newsize = this->_count +1; alcx_io_record* newarr = new alcx_io_record[newsize]; memcpy( newarr, rec, _count * sizeof(alcx_io_record) ); _count = newsize; delete [] rec; rec[0] = newarr; }
i aware i'm wrong on: rec[0] = newarr
but changing rec = newarr
gives me error: "expression must modifiable lvalue"
any solution welcome, thank you.
remove [1] declaration, you're using pointer, not array of pointers declared now. error stems trying overwrite fact declared array - type cannot changed programmatically @ runtime, though it's technically compatible.
Comments
Post a Comment