C++ pointer to array of pointers

I am having trouble figuring how to make a modification to a piece of code for a project I am working on.

The original code is

class foo {

public:
...

private:

uint8_t _size; 
uint8_t *address;
uint8_t *rx_buffer;
}

// And down in a method a call is made to
// Copy the received data into address
memcpy(address, rx_buffer, _size);

And everything works well.

I want to modify it so I can handle multiple addresses so I made the following changes

class foo {

public:
...

private:
uint8_t _size[3];     //size of each struct
uint8_t _key[3];     // the key to identify each struct
uint8_t _index;       // the index of the last struct added
uint8_t *address[3];  //address of each struct
uint8_t *rx_buffer;   //address for temporary storage and parsing
}
 
// Copy received data into address
memcpy(address[index],rx_buffer,_size[index]);

No longer works!
As you can tell, I am not yet a C++ programmer. I am trying to learn with my projects. If someone would be kind enough to tell me how to think about it, I would be much appreciative.

Thanks in advance

My first guess is that you want:

uint8_t (*address)[3];  //address of each struct

instead of:

uint8_t *address[3];  //address of each struct

I think the way you wrote it you have a single pointer to an array containing three bytes. What you want is an array of three pointers pointing to bytes.

memcpy(address[index],rx_buffer,_size[index]);

The declaration looks OK to me, from a C perspective. How is address[] being initialized?

//_index is initialized to 0

void foo::addPointer(uint8_t *ptr, uint8_t length){
_size[_index] = length;
address[_index] = ptr;
_index++;
}

With the snippets you've shown, "index" is going to be pointing to one past the last structure that you initialized...

    address[_index] = ptr;
      _index++;

//   :

memcpy(address[index],rx_buffer,_size[index]);

thats correct, so when I loop through the addresses I know to stop at i < _index;

What is the relationship (if any) between index and _index in this code?

in the example index is a passed in variable to point to one of the addresses. _index is the variable that is used to manage the adding of pointers and how many there are. I don't think it would be a good idea to put all of the code out, as it will just make it more difficult to understand where I am stumped.

Well, I think we need to see more. The current pieces look OK to me.
What does "no longer works" mean, exactly, anyway? Doesn't compile? compiles but hangs when run? Compiles and seems to run but doesn't do the right thing?

I don't see it, too.

Just a quick note: There is an ancient C utility (that's been upgraded for C with crutches) called cdecl. I know that source is freely downloadable from a number of web sites for *nix systems, but I'm not sure if there's a Windows version (if not, it's available as a web resource at sites like http://www.cdecl.org/. Cdecl does 2-way translations between declarations and English. I've found it handy both for unraveling complicated declarations and for coding declarations I wasn't sure how to write.

It translates unsigned char *address[3] to "declare address as array 3 of pointer to unsigned char".

HTH

So my guess was wrong. Please ignore my previous answer.

I think we need all of the code along with a description of the failure symptoms.