建議使用 Visual Studio 2017

編譯器錯誤 C3350

 

如需 Visual Studio 2017 的最新文件請參閱 Visual Studio 2017 文件

'delegate': 委派建構函式必須有 <數字> 個引數

當您建立委派的執行個體時,必須傳遞兩個引數:包含委派函式之類型的執行個體,以及函式。

下列範例會產生 C3350:

// C3350.cpp  
// compile with: /clr  
delegate void SumDelegate();  
  
public ref class X {  
public:  
   void F() {}  
   static void F2() {}  
};  
  
int main() {  
   X ^ MyX = gcnew X();  
   SumDelegate ^ pSD = gcnew SumDelegate();   // C3350  
   SumDelegate ^ pSD1 = gcnew SumDelegate(MyX, &X::F);  
   SumDelegate ^ pSD2 = gcnew SumDelegate(&X::F2);  
}  

Managed 的 Extensions for c + +

下列範例會產生 C3350:

// C3350b.cpp  
// compile with: /clr:oldSyntax  
#using <mscorlib.dll>  
__delegate void SumDelegate();  
  
public __gc class X {  
public:  
   void F() {}  
   static void F2() {}  
};  
  
int main() {  
   X * MyX = new X();  
   SumDelegate *pSD = new SumDelegate();   // C3350  
   SumDelegate *pSD1 = new SumDelegate(MyX, &X::F);  
   SumDelegate *pSD2 = new SumDelegate(&X::F2);  
}  

顯示: