Deprecate Typedef
I have a few TypeDefs that I want to deprecate. I am doing this to retain backward c开发者_JS百科ompatibility with code that already exists. Is there an elegant (or maybe not so elegant) solution to this? I would like it to be platform independent but if there is a Visual Studio only solution, that will do as well.
In MSVC++, you can deprecate typedef
like this:
typedef __declspec(deprecated) int myint;
The MSVC++ compiler will generate warning that myint
is deprecated!
And if you want the compiler to generate a specific message when compiling a deprecated typedef, then do this:
typedef __declspec(deprecated("myint is deprecated, so most likely in the next version this myint will be missing")) int myint;
I know this question is 10 years old, but for anyone still asking this question, this syntax has been supported since C++14:
[[deprecated("reason")]] typedef int type;
If one-off easy code changes are allowed you could just move the typedef into a deprecated
namespace requiring the use of using namespace deprecated
at the points that use the typedef.
If that's not an option it might be possible to concoct a template that, when instantiated, would generate a warning, but I don't know how to generate such a warning offhand:
template <class T>
class TypedefHolder;
template <>
class TypedefHolder<int>
{
typedef int WhateverType;
// Something that induces a compile warning.
};
so instead of:
typedef int WhateverType;
it becomes:
typedef TypedefHolder<int>::WhateverType WhateverType;
精彩评论