I am working with a library that I can't change and have been set a task to complete with the library.
Although I have done the task and it works, I don't really understand why it works and whether I should do it.
I have a function in a cpp file
void Foo (const String &someName) { OtherFoo (&someName) } where Foo passes a reference to a const string and OtherFoo requires a pointer to const string to be passed to it.
So basically ref is a const string& and needs to be passed into OtherFoo as a const pointer (const & to const *)
Is what I've done OK? (passing the address of the ref to the function that requires a pointer to const string)
Is there any negatives with how I have passed the argument? Could someone explain exactly why it works?
Many thanks
const foo *is a pointer-to-const and not a const pointer (that would befoo * const),const foo &is a reference-to-const. Makes things less ambiguous.)Foocan be called with a temporary object and the lifetime of the temporary will be the callFoo. IfOtherFoostores the pointer for later use somewhere and that use happens afterFoois done, the pointer will point to a a dead object.