C ++ / CLI使用Action< ...,...>和Func< ...>不支持? [英] C++/CLI use of Action<...,...> and Func<...> unsupported?

查看:338
本文介绍了C ++ / CLI使用Action< ...,...>和Func< ...>不支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它似乎不支持在C ++ / CLI中的System命名空间中的Action和Func委托。至少不能用于多个泛型参数,例如:

it does not look like there is support for the Action and Func delegates in the System namespace in C++/CLI. At least not for multiple generic arguments such as:

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

两者都会导致错误,例如:

Both result in errors such as:

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

只有单一参数动作有效:

Only single argument Action works:

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

任何人,知道为什么或缺少什么使这项工作。我使用Visual Studio 2008和项目有目标框架3.5。

Anyone, knows why or what is missing to make this work. I am using Visual Studio 2008 and the project has target framework 3.5.

推荐答案

Func 类型会根据您使用的框架版本而有所不同。

The location of the Action and Func types is different depending on the framework version you are using.

在3.5框架中, Func (通用或非通用)的所有定义位于System.Core.dll。对于具有2个或更多通用参数的 Action 版本也是如此。 行动行动< T1,T2> 都在mscorlib。

In the 3.5 framework all definitions of Func (generic or not generic) reside in System.Core.dll. This is also true for versions of Action with 2 or more generic parameters. Action and Action<T1,T2> are in mscorlib though.

在4.0框架中, Func Action 的所有定义都移动到mscorlib。有现在指向mscorlib的System.Core中插入的类型转发器。

In the 4.0 framework all of the definitions of Func and Action moved to mscorlib. There are type forwarders inserted into System.Core which point back to mscorlib now.

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

Silverlight 4.0 is closer to the 3.5 framework solution.

确保您有解决方案的适当DLL的参考。

Make sure you have a reference to the appropriate DLL for your solution.

这篇关于C ++ / CLI使用Action&lt; ...,...&gt;和Func&lt; ...&gt;不支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆