我有几个TypeDef需要弃用。我这么做是为了保留与已经存在的代码的向后兼容性。有没有一种优雅(或者不那么优雅)的解决方案?我希望它是平台无关的,但如果只有Visual Studio的解决方案也可以。
我有几个TypeDef需要弃用。我这么做是为了保留与已经存在的代码的向后兼容性。有没有一种优雅(或者不那么优雅)的解决方案?我希望它是平台无关的,但如果只有Visual Studio的解决方案也可以。
在MSVC++中,您可以这样弃用 typedef
:
typedef __declspec(deprecated) int myint;
MSVC++编译器会生成警告,指出myint
已过时!
如果你希望编译器在编译已过时的typedef时生成特定的消息,则可以这样做:
typedef __declspec(deprecated("myint is deprecated, so most likely in the next version this myint will be missing")) int myint;
#pragma deprecated
,它也适用于宏。 - Cat Plus Plustemplate <class T>
class TypedefHolder;
template <>
class TypedefHolder<int>
{
typedef int WhateverType;
// Something that induces a compile warning.
};
typedef int WhateverType;
it becomes:
typedef TypedefHolder<int>::WhateverType WhateverType;
我知道这个问题已经有10年了,但是对于仍在询问此问题的任何人来说,这个语法从C++14开始就得到了支持:since C++14。
[[deprecated("reason")]] typedef int type;
typedef int myint __attribute__((deprecated));
。 - aschepler