I have a c++ library which has an function called ExampleFunction()
. This function is documented and is already in use. Unfortunately, the style of the library requires this function to be called exampleFunction()
{initial letter is lowercase}.
I need to keep the old name for backwards compatibility but add the new name as a public function. What is the most efficient way to do this?
I am assuming that adding a definition of:
void exampleFunction() {ExampleFunction();}
is not the best way of solving this and am looking for options.
You could rename the existing function that actually has the implementation to exampleFunction()
, since that's what it should be. Then, so users of the old name 1) still have working code, and 2) are told that there's a newer function name to use, you can do this:
[[deprecated("Use exampleFunction() instead")]]
inline void ExampleFunction() { exampleFunction(); }
This uses the deprecated
attribute from C++14 and later. The performance hit for the wrapper function is either non-existent (if really inlined by the compiler) or negligible.