I'm looking through an API written in C++ and I'm confused as to what the following parameter type means:
void*& data
Does that mean the user would pass in a reference to a void pointer? If that's true, what's the point? I mean void* is already indirected so why would you ever want to redirect it again?
void *
means pass-by-pointer in C++, meaning you pass in a pointer, but it's actually a copy of the pointer. If you modified this pointer in your function, like changing its address, it is not reflected in the pointer you passed in.
Combining that with pass by reference, void *&
means you are passing an alias of the original pointer to this function. If you modified it, like changing its address, it will be reflected in the original pointer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With