共用方式為


編譯器錯誤 C3104

更新:2007 年 11 月

錯誤訊息

不合法的屬性引數

您對屬性指定了無效的引數。

如需詳細資訊,請參閱Attribute Parameter Types

對 Visual C++ 2005 的編譯器完成一致性處理後可能會發生這項錯誤:傳遞 Managed 陣列給自訂屬性時,陣列的型別不再是從彙總初始設定清單中推算得出。現在編譯器要求您指定陣列的型別以及初始設定式清單。如需詳細資訊,請參閱Visual C++ 2005 編譯器的重大變更

範例

下列範例會產生 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{};

下列範例會產生 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 {};

下列範例會產生 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 {};