Edit

Share via


Deprecating types and members (C++/CX)

C++/CX supports deprecation of Windows Runtime types and members for producers and consumers by using the Deprecated attribute. If you consume an API that has this attribute, you get a compile-time warning message. It indicates that the API is deprecated and also recommends an alternative API to use. In your own public types and methods, you can apply this attribute and supply your own custom message.

Caution

The Deprecated attribute is for use only with Windows Runtime types. For standard C++ classes and members, use [[deprecated]] (C++14 and later) or __declspec(deprecated).

Example

The following example shows how to deprecate your own public APIs—for example, in a Windows Runtime component. The second parameter, of type Windows:Foundation::Metadata::DeprecationType specifies whether the API is being deprecated or removed. Currently only the DeprecationType::Deprecated value is supported. The third parameter in the attribute specifies the Windows::Foundation::Metadata::Platform to which the attribute applies.

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();
};

Supported targets

The following table lists the constructs to which the Deprecated attribute may be applied:

class
enum
event
method
property
struct field

delegate
enum field
interface
parameterized constructor
struct
XAML control

See also

Type system (C++/CX)
C++/CX language reference
Namespaces reference