编译器错误 C3099

“关键字”:将 [System::AttributeUsageAttribute] 用于托管特性;将 [Windows::Foundation::Metadata::AttributeUsageAttribute] 用于 WinRT 特性

使用 AttributeUsageAttribute 声明“/clr”特性。 使用 Windows::Foundation::Metadata::AttributeUsageAttribute 声明 Windows 运行时特性。

有关 /CLR 特性的详细信息,请参阅用户定义的特性。 有关 Windows 运行时支持的特性,请参阅 Windows.Foundation.Metadata 命名空间

示例

下面的示例生成 C3099,并演示如何修复此错误。

// C3099.cpp
// compile with: /clr /c
using namespace System;
[usage(10)]   // C3099
// try the following line instead
// [AttributeUsageAttribute(AttributeTargets::All)]
ref class A : Attribute {};