Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 817
Chris Andrews Avatar asked Dec 03 '22 15:12

Chris Andrews


2 Answers

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.

like image 52
MSalters Avatar answered Dec 09 '22 14:12

MSalters


Only using compiler dependent pragmas: look up the documentation

 int old_fn () __attribute__ ((deprecated));
like image 37
dirkgently Avatar answered Dec 09 '22 16:12

dirkgently