【问题标题】:#pragma deprecate a function based on signature?#pragma 弃用基于签名的函数?
【发布时间】:2011-01-27 17:58:11
【问题描述】:

在 Visual Studio 中,是否可以根据函数的签名而不是简单的名称来#deprecated 函数?

在我的例子中,我们使用 C++ 并且不想弃用该函数的所有风格

int foo();        <-- we want to keep
int foo(int x);   <-- we want to deprecate

【问题讨论】:

    标签: c++ visual-c++ deprecated


    【解决方案1】:

    这样做:

    __declspec(deprecated) void foo(int) {}
    

    如果您希望编译器在编译已弃用的函数时生成特定消息,请执行以下操作:

    __declspec(deprecated("foo(int) is a deprecated function.")) void foo(int) {}
    

    【讨论】:

    • 比我快 40 秒。该死的你! +1 :)
    【解决方案2】:

    deprecated may also be specified in a __declspec(),(这甚至比#pragma 更好,因为它允许您在需要时提供原因。

    【讨论】:

      猜你喜欢
      • 2020-04-07
      • 1970-01-01
      • 2012-08-25
      • 2015-02-03
      • 1970-01-01
      • 2021-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多