Reputation: 2083
I have seen code in several places where you have a function qualified by a user defined keyword. For example
#define EXTERNAL_API dec __declspec(dllexport)
and then we have a function call
void EXTERNAL_API doStuff() {}
I understand the purpose in this case but I want to know if these qualifiers can be used to perform specific behavior on functions that are qualified with this. For example, if I want to mark a function as deprecated in my class and if I make use of this function call elsewhere, I get a compile time warning that this function is deprecated, use doStuff2() instead. How can I achieve this functionality?
Upvotes: 1
Views: 72
Reputation: 321
Each compiler has its own keywords to mark function as deprecated, for MSVS you can do the following:
#define DEPRECATED __declspec(deprecated(COMPILE_ERROR_TEXT))
and you can use it as:
DEPRECATED void oldFunction();
In C++14 there is a possibility to use [[deprecated]] tag. Like that:
[[deprecated]]
void oldFunc();
I hope that will help you.
Upvotes: 2