C ++标记为已弃用 [英] C++ mark as deprecated

查看:755
本文介绍了C ++标记为已弃用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在接口中有一个方法,我想使用便携式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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆