c ++标记枚举值已被弃用? [英] c++ mark enum value as deprecated?
本文介绍了c ++标记枚举值已被弃用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如
enum MyEnum {
firstvalue = 0
secondvalue,
thirdvalue,// deprecated
fourthvalue
};
二等奖解决方案将是ifdef的MSVC和GCC解决方案。
解决方案
你可以这样做:
枚举MyEnum {
firstvalue = 0,
secondvalue,
thirdvalue,// deprecated
fourthvalue
};
#pragma deprecated(thirdvalue)
然后,当使用变量时,编译器将输出以下内容:
警告C4995:'thirdvalue':名称标记为#pragma已弃用
编辑
这看起来有点黑客,我没有GCC编译器来确认(可以有人为我做这个),但它应该工作:
枚举MyEnum {
firstvalue = 0,
secondvalue,
#ifdef _MSC_VER
thirdvalue,
#endif
fourthvalue = secondvalue + 2
};
#ifdef __GNUC__
__attribute__((已弃用))const MyEnum thirdvalue = MyEnum(secondvalue + 1);
#elif defined _MSC_VER
#pragma deprecated(thirdvalue)
#endif
这是我的答案和MSalters的回答
的组合
Is it possible to mark an enum value as deprecated?
e.g.
enum MyEnum {
firstvalue = 0
secondvalue,
thirdvalue, // deprecated
fourthvalue
};
A second prize solution would be to ifdef a MSVC and a GCC solution.
解决方案
you could do this:
enum MyEnum {
firstvalue = 0,
secondvalue,
thirdvalue, // deprecated
fourthvalue
};
#pragma deprecated(thirdvalue)
then when ever the variable is used, the compiler will output the following:
warning C4995: 'thirdvalue': name was marked as #pragma deprecated
EDIT
This looks a bit hacky and i dont have a GCC compiler to confirm (could someone do that for me?) but it should work:
enum MyEnum {
firstvalue = 0,
secondvalue,
#ifdef _MSC_VER
thirdvalue,
#endif
fourthvalue = secondvalue + 2
};
#ifdef __GNUC__
__attribute__ ((deprecated)) const MyEnum thirdvalue = MyEnum(secondvalue + 1);
#elif defined _MSC_VER
#pragma deprecated(thirdvalue)
#endif
it's a combination of my answer and MSalters' answer
这篇关于c ++标记枚举值已被弃用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文