Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

[C++] Allocating local variables

Name: Anonymous 2012-09-02 0:12

Shouldn't this be working? I'm trying to point all three pointers to this new int array, but the address isn't right.

<code>void allocate(int a[], int * &x, int ** &y, int *** &z)
{
    a = new int [ 5 ];

    x = a;
    y = new int*;
    *y = a;
    z = new int**;
    *z = new int*;
    **z = a;

    return;
}

int main()
{
    int arr[5];

    int *ptrX;
    int **ptrY;
    int ***ptrZ;

    // Allocate the dynamic memory
    allocate(arr, ptrX, ptrY, ptrZ);

    return 0;
}</code>

Name: Anonymous 2012-09-02 2:09

>>6
And that part works. The plant looses its leaves and turns brown fine, but the other three plants don't contain the same number of lost leaves and level of brownness. They won't turn brown.

>>8
a is a reference to a pointer, and in the context of how it is called, it is a reference to an array.

>>11
it was a reference

>>12
The function by itself is ok, but not in the context in how it is called. Look at what it is trying to do. Is it defined?

>>15
A house is really just a vehicle. Use a vehicle. You're welcome.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List