Partilhar via


Erro do compilador C3450

«tipo»: não é um atributo; não é possível especificar [System::AttributeUsageAttribute] ou [Windows::Foundation::Metadata::AttributeUsageAttribute]

Observações

Um atributo gerenciado definido pelo usuário deve herdar do AttributeCollection. Um atributo do Tempo de Execução do Windows deve ser definido no Windows::Foundation::Metadata namespace.

Para obter mais informações, consulte Atributos Definido pelo Usuário.

Example

O exemplo a seguir gera C3450 e mostra como corrigi-lo.

// 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 {};