Compilerfehler C3351
Aktualisiert: November 2007
Fehlermeldung
'Objekt': Delegatkonstruktor: zweites Argument muss Adresse einer statischen Memberfunktion oder globalen Funktion sein
'object' : delegate constructor: second argument must be address of a static member function or global function
Der Compiler hat die Adresse einer als static deklarierten Funktion erwartet.
Im folgenden Beispiel wird C3351 generiert:
// C3351a.cpp
// compile with: /clr
delegate int D(int, int);
ref class C {
public:
int mf(int, int) {
return 1;
}
static int mf2(int, int) {
return 1;
}
};
int main() {
System::Delegate ^pD = gcnew D(nullptr, &C::mf); // C3351
System::Delegate ^pD2 = gcnew D(&C::mf2);
}
Im folgenden Beispiel wird C3351 generiert:
// C3351b.cpp
// compile with: /clr:oldSyntax
#using <mscorlib.dll>
__delegate int D(int, int);
__gc class C {
public:
int mf(int, int) {
// declare the function as static
// static int mf(int, int) {
return 1;
}
};
int main() {
C *pC = new C;
System::Delegate *pD = new D(0, &C::mf); // C3351
}