C ++标记为已弃用 [英] C++ mark as deprecated
问题描述
我在接口中有一个方法,我想使用便携式C ++弃用。
当我Googled这一切,我得到的是一个Microsoft特定的解决方案; #pragma已弃用和__declspec(deprecated)。
I have a method in an interface that I want to deprecate with portable C++. When I Googled for this all I got was a Microsoft specific solution; #pragma deprecated and __declspec(deprecated).
二等奖解决方案到ifdef的MSVC和GCC解决方案。
感谢
A second prize solution would be to ifdef a MSVC and a GCC solution.
Thanks
推荐答案
p>
This should do the trick:
#ifdef __GNUC__
#define DEPRECATED(func) func __attribute__ ((deprecated))
#elif defined(_MSC_VER)
#define DEPRECATED(func) __declspec(deprecated) func
#else
#pragma message("WARNING: You need to implement DEPRECATED for this compiler")
#define DEPRECATED(func) func
#endif
...
//don't use me any more
DEPRECATED(void OldFunc(int a, float b));
//use me instead
void NewFunc(int a, double b);
std :: pair< int,int>
,因为这将被预处理器解释为传递2个参数到DEPRECATED宏。
However, you will encounter problems if a function return type has a commas in its name e.g. std::pair<int, int>
as this will be interpreted by the preprocesor as passing 2 arguments to the DEPRECATED macro. In that case you would have to typedef the return type.
编辑:更简单(但可能兼容性较差)的版本此处。
simpler (but possibly less widely compatible) version here.
这篇关于C ++标记为已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!