Chr*_*ews 3 c++ compiler-construction attributes
有没有一种方法可以将C++中的方法/类标记为过时的?
在c#中你可以写:
[Obsolete("You shouldn't use this method anymore.")]
void foo() {}
Run Code Online (Sandbox Code Playgroud)
如果重要的话我使用GNU工具链/ Eclipse CDT.
仅使用编译器相关的编译指示:查找文档
int old_fn () __attribute__ ((deprecated));
Run Code Online (Sandbox Code Playgroud)
最简单的方法是使用#define DEPRECATED
.在GCC上,它扩展到__attribute__((deprecated))
,在Visual C++上它扩展到__declspec(deprecated)
,并且在没有silimar的编译器上它扩展为空.
c++14 标准(或更高版本)现在提供此功能:https://en.cppreference.com/w/cpp/language/attributes/deprecated
[[deprecated]] void F();
[[deprecated("reason")]] void G();
class [[deprecated]] H { /*...*/ };
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3075 次 |
最近记录: |