Share via


將類型和成員設為已被取代 (C++/CX)

C++/CX 支援使用 Deprecated 屬性來取代生產者和取用者Windows 執行階段類型和成員。 如果您使用具有這個屬性的 API,您會收到編譯時期警告訊息。 它表示 API 已被取代,也建議使用替代的 API。 在您自己的公用類型和 method s 中,您可以套用此屬性並提供您自己的自訂訊息。

警告

屬性 Deprecated 僅適用于Windows 執行階段型別。 針對標準 C++ class 和成員,請使用 [[deprecated]] (C++14 和更新版本) 或 __declspec(deprecated)

範例

下列範例示範如何 (例如在 Windows 執行階段元件中) 將您的公用 API 設為已被取代。 類型的 Windows:Foundation::Metadata::DeprecationType 第二個參數會指定 API 即將淘汰或移除。 目前僅 DeprecationType::Deprecated 支援值。 屬性中的第三個參數會 Windows::Foundation::Metadata::Platform 指定套用屬性的 。

namespace wfm = Windows::Foundation::Metadata;

public ref class Bicycle sealed
{

public:
    property double Speed;

    [wfm::Deprecated("Use the Speed property to compute the angular speed of the wheel", wfm::DeprecationType::Deprecate, 0x0)]
    double ComputeAngularVelocity();
};

支援的目標

下表列出套用屬性的 cons structDeprecated

class
enum
event
method
property
struct field

delegate
enum field
interface
參數化 con struct 或
struct
XAML 控制項

另請參閱

類型系統 (C++/CX)
C++/CX 語言參考
命名空間參考