Example of Allocating Storage with new()


/***********************************************************************
*

In the following example, storage is allocated for an array of pointers to functions:

                                                                        *
************************************************************************/

void f();
void g();
void main()
{
      void (**p)(), (**q)();
      // declare p and q as pointers to pointers to void functions
      p = new (void (*[3])());
      // p now points to an array of pointers to functions
      q = new void(*[3])(); // error
      // error - bound as 'q = (new void) (*[3])();'
      p[0] = f;  // p[0] to point to function f
      q[2] = g;  // q[2] to point to function g
      p[0]();    // call f()
      q[2]();    // call g()
}

/************************************************************************
*

However, the second use of new causes an erroneous binding of q = ( new void) (*[3])().

                                                                        *
************************************************************************/