[c++] [[deprecated]] attribute
To apply the [[deprecated]]
attribute to a function in C++, you can do the following:
[[deprecated("Use better_alternative_function() instead")]]
void old_function() {
// function implementation
}
In this example, the [[deprecated]]
attribute is applied to the old_function()
to indicate that it should no longer be used, and the message provides a suggestion for an alternative function to use.
When compiling code with the [[deprecated]]
attribute, the compiler will generate a warning message to alert the developer about the usage of deprecated functions, classes, or variables.
It’s good practice to provide a clear message explaining why the item is deprecated and what alternative should be used instead.
References:
- C++ documentation on deprecated attribute: C++ Deprecated Attribute
- C++ Standard (ISO/IEC 14882:2017) - 9.11 Deprecated attribute: ISO C++ Standard - 9.11 Deprecated attribute