2010-02-03 65 views
4

它看起來好像不支持C++/CLI中System命名空間中的Action和Func委託。至少對於多個​​通用參數,如:C++/CLI使用行動<...,...>和Func <...>不受支持?

System::Action<int, int>^ action = nullptr; 
System::Func<int, int>^ func = nullptr; 

兩種結果中的錯誤,如:

error C2977: 'System::Action' : too many generic arguments 
error C2955: 'System::Action' : use of class generic requires generic argument list 

只有一個參數動作作品:

System::Action<int>^ action = nullptr; 

任何人,知道爲什麼還是什麼缺少使這項工作。我正在使用Visual Studio 2008,該項目有目標框架3.5。

+0

您是否有對System.Core的引用? – 2010-02-03 17:25:52

回答

8

根據您使用的框架版本,ActionFunc類型的位置有所不同。

在3.5框架中,Func(通用或非通用)的所有定義都駐留在System.Core.dll中。具有2個或更多通用參數的Action版本也是如此。 ActionAction<T1,T2>雖然在mscorlib中。

在4.0框架中,所有FuncAction的定義都被移到了mscorlib中。 System.Core中插入了類型轉發器,它現在指向mscorlib。

Silverlight 4.0更接近3.5框架解決方案。

請確保您有解決方案的相應DLL的引用。

+0

確實如此。添加System.Core.dll解決了這些問題。謝謝。 – nietras 2010-02-04 08:14:42

+0

您提到System.Core for 4.0中的類型轉發器。你知道如何做到這一點嗎? – nietras 2010-02-04 08:25:17

8

以下是mscorlib中定義 -

Action 
Action<T> 

但以下是System.Core程序定義。

Action<T1, T2> 
Func<T1, T2> 

您可能會錯過對該程序集的引用。

相關問題