Compartir a través de


Error del compilador C3104

Actualización: noviembre 2007

Mensaje de error

argumento de atributo no válido
illegal attribute argument

Se especificó un argumento no válido para un atributo.

Vea Attribute Parameter Types para obtener más información.

Este error puede producirse como resultado del trabajo de conformidad del compilador realizado para Visual C++ 2005: cuando se pasan matrices administradas a atributos personalizados, el tipo de matriz ya no se deduce de la lista de inicialización de agregado. Ahora el compilador requiere que se especifique el tipo de la matriz así como la lista de inicializadores. Vea Cambios importantes en el compilador de Visual C++ 2005 para obtener más información.

Ejemplo

El ejemplo siguiente genera el error C3104.

// C3104a.cpp
// compile with: /clr /c
using namespace System;

[AttributeUsage(AttributeTargets::Class)]
public ref struct ABC : public Attribute {
   ABC(array<int>^){}
   array<double> ^ param;
};

[ABC( {1,2,3}, param = {2.71, 3.14})]   // C3104
// try the following line instead
// [ABC( gcnew array<int> {1,2,3}, param = gcnew array<double>{2.71, 3.14})] 
ref struct AStruct{};

El ejemplo siguiente genera el error C3104.

// C3104b.cpp
// compile with: /clr /c
// C3104 expected
using namespace System;

int func() {
   return 0; 
}

[attribute(All)]
ref class A {
public: 
   A(int) {}
};

// Delete the following 2 lines to resolve.
[A(func())]
ref class B {};

// OK
[A(0)]
ref class B {};

El ejemplo siguiente genera el error C3104.

// C3104c.cpp
// compile with: /clr:oldSyntax /c
using namespace System;

[ attribute(Class) ]
public __gc class AnotherAttr {
public:
   AnotherAttr(Object* arr __gc[]) : var0(arr) {}
   Object* var1 __gc[];
   Object* var0 __gc[];
};

[ AnotherAttr( { __box(3.14159), S"pi" }, var1 = { S"a", S"b" } ) ]   // C3104
public __gc class Class1 {};

// OK
[ AnotherAttr( new Object * __gc[] {__box(3.14159), S"pi" }, var1 = new Object * __gc[] { S"a", S"b" } ) ]
public __gc class Class2 {};