How to use templates with C++/CLI 2010?

血红的双手。 提交于 2019-12-13 07:37:49

问题


I've got following method in c#:

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

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

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

where I'm getting

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

what am I doing wrong?


回答1:


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

Try

array<UrlInfo>^ arr

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.



来源:https://stackoverflow.com/questions/9057565/how-to-use-templates-with-c-cli-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!