View Single Post
Old 06-20-2005, 10:56 AM   #1 (permalink)
Rekna
Junkie
 
[C++] passing pointers by reference?

Is it possible to pass a pointer in C++ by reference without just using a double pointer?

I have some code that should work but the refrence portion of it does not seem to be working.

Here is a function similar to what i want to do without all the details.



Code:
void foo(int *&a)
{
   int* b=new int[10];

   //loop some number of times
         //Do some copy operation from b to a
         
         swap(a,b);

   delete[] b;
}
When this code exits a should contain the values, unfortunatly right now this is only true if the loop executes an even number of times.
Rekna is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37