Search code examples
.netc++-clivisual-c++-2010

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


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?


Solution

  • 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.