c++attributes

Mark class/method obsolete or deprecated in C++


Is there a way of marking methods/classes in C++ as obsolete?

In c# you can write:

[Obsolete("You shouldn't use this method anymore.")]
void foo() {}

I use the GNU toolchain/Eclipse CDT if that matters.


Solution

  • The easiest way is with a #define DEPRECATED. On GCC, it expands to __attribute__((deprecated)), on Visual C++ it expands to __declspec(deprecated), and on compilers that do not have something silimar it expands to nothing.