Deprecated attribute in C++14 with Examples
Last Updated :
28 Jan, 2021
In this article, we will discuss Deprecated attribute in C++14. Deprecated means the use of the name or entity declared with this attribute is allowed but discouraged for some reason. The compiler gives warnings and if string literals are provided, they are included in warnings.
Program 1:
For example, let’s consider the following program of multiplication of two numbers:
C++14
#include <iostream>
using namespace std;
int multiply( int a, int b)
{
return a * b;
}
int main()
{
int a = 2, b = 4;
cout << multiply(a, b);
return 0;
}
|
Explanation: In the above program, a multiplication operation has been performed with the help of a simple function named multiply.
Now, to tell the programmers that this approach is outdated, perform another approach by deprecating the function using the below syntax:
[[deprecated (“Write your message”)]]
Program 2:
C++14
#include <iostream>
using namespace std;
[[ deprecated ( "This method is outdated, use any other approach" )]]
int
multiply( int a, int b)
{
return a * b;
}
int main()
{
int a = 2, b = 4;
cout << multiply(a, b);
return 0;
}
|
Output:
Lists of what can be deprecated are as follows:
Share your thoughts in the comments
Please Login to comment...