如何在C ++ / CLI 2010中使用模板? [英] How to use templates with C++/CLI 2010?

查看:86
本文介绍了如何在C ++ / CLI 2010中使用模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在c#中有以下方法:

I've got following method in c#:

    public static T[] GetResult<T>(ulong taskId)
    {
        return GetResult(taskId).Cast<T>().ToArray();
    }  

我正在尝试在托管c ++ 2010中使用它,如下所示:

and I'm trying to use it in managed c++ 2010 like this:

array<UrlInfo^>^ arr=Scheduler::GetResult<UrlInfo>(taskId);

我要去的地方

Error   3   error C2770: invalid explicit generic argument(s) for 
'cli::array<Type,dimension> 

我在做什么错了?

推荐答案

如果 UrlInfo 是值类型,则您不希望 ^

If UrlInfo is a value type, you don't want the ^.

尝试

array<UrlInfo>^ arr

如果 UrlInfo 是引用类型,则需要 ^ 调用 GetResult 时。

If UrlInfo is a reference type, you need a ^ when calling GetResult.

arr=Scheduler::GetResult<UrlInfo^>(taskId);

无论哪种方式都出了问题。根据错误消息,我认为这是第一种情况。

Either way something's wrong. Based on the error message, I think it's the first case.

这篇关于如何在C ++ / CLI 2010中使用模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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