Deprecate old name for class in C++
c++, c-preprocessor, deprecated, macros, typedef
Solution
As said by others, this is very compiler specific. Assuming your classes are defined with the new name. Here is what you can do with GCC and MSVC:
class NewClassA {}; // Notice the use of the new name.
// Instead of a #define, use a typedef with a deprecated atribute:
// MSVC
typedef NewClassA __declspec(deprecated) OldClassA;
// GCC
//typedef NewClassA __attribute__((deprecated)) OldClassA;
int main(){
NewClassA newA;
OldClassA oldA;
}
MSVC yields:
warning C4996: 'OldClassA': was declared deprecated
GCC yields:
warning: 'OldClassA' is deprecated
No warning is emmited for `NewClassA newA;` by either compiler.
Problem
I work on a framework that has massively renamed all its classes and functions, I created a transition header allowing to use old names: ``` #define OldClassA NewClassA #define OldClassB NewClassB ... ``` Now I would like the compiler to warn the user when the old name is used. How can I do this? ``` int main(){ NewClassA newA; OldClassA oldA; // <-- This one would emit a warning } ```