Udostępnij za pomocą


Błąd kompilatora C3450

"type": a nie atrybut; program nie może określić parametru [System::AttributeUsageAttribute] lub [Windows::Foundation::Metadata::AttributeUsageAttribute]

Uwagi

Atrybut zarządzany zdefiniowany przez użytkownika musi dziedziczyć z AttributeCollectionklasy . Atrybut środowisko wykonawcze systemu Windows musi być zdefiniowany w Windows::Foundation::Metadata przestrzeni nazw.

Aby uzyskać więcej informacji, zobacz Atrybuty zdefiniowane przez użytkownika.

Przykład

Poniższy przykład generuje kod C3450 i pokazuje, jak go naprawić.

// C3450.cpp
// compile with: /clr
// C3450 expected
using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;

public ref class MyClass {};

class MyClass2 {};

[attribute(AttributeTargets::All)]
ref struct AtClass {
   AtClass(Type ^) {}
};

[attribute(AttributeTargets::All)]
ref struct AtClass2 {
   AtClass2() {}
};

// Apply the AtClass and AtClass2 attributes to class B
[AtClass(MyClass::typeid), AtClass2]
[AttributeUsage(AttributeTargets::All)]
// Delete the following line to resolve.
ref class B {};
// Uncomment the following line to resolve.
// ref class B : Attribute {};