How to make a array a reference variable?

can someone show me how I make this array on the heap a reference array so that all my function can use it. Bellow is my attempted but its not woking. Thanks for all the help!
1
2
3
4
//Arrays on the heap.
    string* arrayNames = nullptr;
    arrayNames = new string[students];
    string& arrayNamesRef = arrayNamesRef;
You can't to that. The size of the array is part of the type and types are fixed at compile time so there is no way you can get a reference type to a dynamically allocated array because the size is decided at runtime.
so that all my function can use it
What do your function declarations look like?

try this, function declaration:
void myfunc(string* array, int size);

allocate the array like this:
string* arrayNames = new string[students];

and call the function like this:
myfunc(arrayNames , students);
Last edited on
Topic archived. No new replies allowed.