I have a function void update(gsl_vector * x) and as the name suggests update changes the vector x points to. I would like to use update to work on x, but x is a private variable to another class that update is not member of. x has a mutator function set_x(gsl_vector *myX).
My solution at the moment is to create a temporary pointer temp, update temp and then mutate x using the updated temp:
Whether there is a copy overhead depends on the contents of set_x(). It doesn't have to do copying, since it is only dealing with pointers, but it probably does, since pointing to shared memory, without smart pointers can end badly.
So, unless there is such getter, which makes encapsulation pointless, there is not way to avoid copying with your update(). Is there some reason why you don't want it to be a friend or member ?