Thursday, December 10, 2015

c++ change pointer passed as argument

To change the pointer passed in argument you need something like this:
void foo(int **ptr) //pointer to pointer
{
    *ptr = new int[10]; //just for example, use RAII in a real world
}
or
void bar(int *& ptr) //reference to pointer (a bit confusing look)
{
    ptr = new int[10];
}
 
Original thread:  http://stackoverflow.com/questions/11842416/function-does-not-change-passed-pointer-c

No comments:

Post a Comment