/* ... */
private:
unsigned char** a;
/* ... */
void foo::init_a()
{
this->a = new unsigned short*[SIZE];
for (int i=0; i<size; i++)
this->a[i] = new unsigned short[SIZE];
}
/* ... */
unsigned short** foo::gen_a()
{
/*
* Generating unsigned short** b array
*/
return b;
}
/* ... */
void foo::func()
{
this->init_a();
this->a = this->gen_a(); // Error here
}
/*... */
How to set 2d returned array from function to another array?
Functions gen_a() and init_a() well-working;
memcpy(this->a, this->gen_a(), sizeof(this->gen_a)) not working.
Size of array a = size of temp array b from gen_a() function?
Since you’re doing everything yourself, you have to be careful to do everything. (A 2D
std::vector<std::vector<char> >has a working copy constructor, it’s automatic).In this case, your 2D array is built as a 1D array of pointers to 1D arrays. You need to
memcpyevery 1D array.