Actually, I don't know it, but I wouldn't be suprised if all CLI template instantiations were private and not exposable through the public assembly interface. You know, the template types generated by C++/CLI aren't really helpful when talking to other .Net assemblies, and "talking to other .Net" is just what C++/CLI is for.
"Native C++ templates" if (I can call them like that) are usable and accessible only from C++ side. CLR runtime cannot operate on them in general, as the C++ part of the compiler is not able to generate proper type description for these. (*)
For creating .Net interfaces, use .Net BCL types. Use generics instead of templates. So, look at types like System.Collections.Generic.List<>
. They can safely be exposed in public interfaces. (**)
Remember that C++/CLI is a mixture of native C++ and .Net. You get easy access to both worlds, but those worlds doesn't really like being mixed ;)
EDIT:
(*) As JochenKalmbach reminded, it applies to the "native" templates. Microsoft has prepared a special STL version that implements some of the core collection interfaces, hence its vector
actually implements System.Collection.Generic.IEnumerable
. That vector
here is still subject to native restriction and cannot be published through asembly interface directly as itself (as vector<>
). However, the latter type (IEnumerable
) is completely normal CLR type and can be exposed. So, try for example:
System::Collections:::Generic::ICollection<int>^ MyClass::ListOfNumbers()
{
cliext::vector<int>^ devs = gcnew cliext::vector<int>();
devs->push_back(1);
return devs;
}
It probably will compile - but I've not checked.