What is wrong with my template function?

Started by
21 comments, last by Leiarchy9 20 years, 2 months ago
I now got my code working but there was a reason why I had Process() take a dataType*& was because I wanted to change the pointer''s value like so:

template<typename dataType, int MAX>void Process( dataType * pArray, dataType paramValue ){     for( int index = 0; index < MAX; index++ )     {             pArray[index] = paramValue;     }}


Now you said that I only need to use the reference sign when I''m changing the pointer itself not the data it points to. I''m assuming that what you mean by ''the pointer itself'' is ''pArray''? So that would mean that ''pArray(index]'' would be the data it points to right?

--------
"Do you believe in Ghost?"
--------"Do you believe in Ghost?"
Advertisement
Right.

int array[5];array is a constant pointer, its value being the start of the array, and array[0] is the first element, the element array points to.You would need a *& if you wanted to do thisvoid allocate_mem(int*& array){   array = new int[5];}, becausevoid allocate_mem(int* array){   array = new int[5];}wouldn''t do the job, as array wouldn''t be changed outside the function, since the pointer is passed by value. 




blah blah blah.
I understand now. Thanks.

--------
"Do you believe in Ghost?"
--------"Do you believe in Ghost?"

This topic is closed to new replies.

Advertisement