編譯器錯誤 C3104
不合法的屬性引數
您為屬性指定了無效的自變數。
如需詳細資訊,請參閱 屬性參數類型 。
這個錯誤可能會因為 Visual Studio 2005 的編譯程式一致性工作而產生:將 Managed 陣列傳遞至自定義屬性時,不再從匯總初始化清單中推斷數位的類型。 編譯程式現在需要您指定數位的類型以及初始化表達式清單。
範例
下列範例會產生 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 {};