Say I have a function that takes a const reference to a pointer…
Example:
void Foo( const Bar *&p_Thing, );
and I pass a pointer
Bar *blah = NULL; // Initialized when program starts up
to the function
Foo( blah );
I may encounter a compiler error like this
invalid initialization of reference of type 'const Bar*&' from expression of type 'Bar*'
This has happened to me a few times, and I’d really like to clear up how const operates in terms of applying to parameters in relation to argument passing. Any help is appreciated, thanks.
This is what you want:
Then it becomes a const-reference to a
Bar *pointer, which has the lovely feature of compiling.