编译器错误 C3104
非法属性参数
你为属性指定了无效参数。
有关详细信息,请参阅属性参数类型。
为 Visual Studio 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 {};