Let's assume some third-party developer writes a function
int GetErrorCode(const object * p);
This function returns only certain int
values, thus I am tempted to write my own ErrorCode
enum class, that contains all the possible return values. Then write a bit updated function:
enum class ErrorCode : int {};
ErrorCode GetErrorCode2(const object * p){
return (ErrorCode)GetErrorCode(p);
}
The problem is I want my function to be named GetErrorCode
and not that less-intuitive GetErrorCode2
.
How can I possibly achieve that? Maybe there is a way to swap function names or something?
Use namespaces:
namespace MyLibrary {
ErrorCode GetErrorCode(const object *p) {
int origResult = ::ErrorCode(p);
// use :: to explicitly call outer function to avoid recursion
...
}
}
Then you can call the function as:
MyLibrary::GetErrorCode(obj);
Put your function in a namespace that you normally use. You might have a using namespace foo;
- er better yet, using foo::GetErrorCode;
- for it where you use it, preferably in a function's body.
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