Passing array of pointers to a function

I have a class called menu, inside it I have a two dimensional array of pointers to other menu objects called menulist declared by menu*** menulist (pointer an array of an array of pointers). So each menu object has a menulist of other menu objects

class menu
{
public:
  int type;
  char name[10];
  byte color;
  byte xpos;// position on the screen
  byte ypos;
  //byte index[2]; //position in the current menu index
  menu*** menulist; //indexed array pointer to group members
  menu* previous_menu; //pointer to previous menu
  void *value;
  void (*function) ();


  menu(char *myname="", byte y=0, byte x=0, int c_type=0, byte m_color=0)
  {
    strcpy(name, myname);
    color=m_color;
    type=c_type;
    menulist=0;
    previous_menu=0;
    value=0;
    function=0;

    if (y>0)
    {
      menulist = new menu**[y+1];
      menulist[y]=0;
      for (byte i=0; i<y; i++)
      { 
        menulist[i] = new menu*[x+1];
        for (byte p=0; p<=x; p++)
          menulist[i][p]=0;
      }
      
    }
  }

Now I want to manipulate the contents of a menulist by passing it by reference to a function. The following function wants to find the Y length of menulist[Y]

    int max_yindex(const (menu***)& menulist)
  {
    int count;
   for (i=0; menulist[i]!=0; i++)
   count++;


   return count;
   
  }

It should expect the address of a menulist array, but it says ‘menu’ was not declared in this scope. Both the function max_yindex() and the class menu were declared before the “setup” routine. What is the correct parameter for the max_yindex function?

Why on earth are you mixing pointers and references? That sounds like a recipe for mass confusion. Pick one or the other, and stick with that one. References, while really just pointers under the sheets, were created to "clean up" the often ugly and error-prone pointer syntax. Pretty much anything that can be done with one, can be done with the other, but references are generally better "style".

Also, when you get into syntax like "***", you really need to re-consider your data representations. That, too, is a recipe for confusion, and both things will lead to some horrendously difficult to fine bugs. Poor data structures WILL lead to complicated, buggy, unreliable code, as sure as the day is long.

I would seriously consider using linked lists rather than multiple levels of indirection. It will be FAR easier to understand, and FAR easier to keep track of, which will lead to far fewer really nasty bugs. And, you'll almost certainly end up with less code overall.

Regards,
Ray L.

This is my attempt at a linked list tree. Each menu object contains a "list" in the form of a 2d array, of other menu objects. So I am simply asking how to pass a menu object's menulist to a function in the way I have set it up.

I don't know how I've "mixed" pointers and references. How about you pick the one I have implemented, and work with that?

Each menu object contains a "list" in the form of a 2d array

If you are working with 2d arrays, then menu*** is probably not the correct type.

If you have a 2d array
char[10][20];

Then the elements of that array are not pointers to chars, they are arrays of 20 chars. The correct type is (char()[20]), or equivalently (char[][20]), A pointer to a pointer to such an array is (char(**)[20]), or (char()[20]).

Oh hang on, when you say "two dimensional array of pointers", you don't actaully mean "two dimensional array of pointers", you mean you are using an array of pointers to simulate a ragged array (or whatever they are called).

Carry on.