Create the following generic IEnumerable in CLI / C ++?

how can you create the following generic IEnumerable in CLI / C ++:

IEnumerable<T> Fetch<T>() where T: MyFetch, new() { }

I tried something, but did not find a solution that looks โ€œlegitimateโ€ and fits my needs.

I want the function to be part of the class

+4
source share
2 answers

You do not use ^ hat in the where clause. It names the type, not the type descriptor, which you would use to declare a variable or parameter. The T type parameter is already entered by the generic keyword, you do not apply it again to the method name, as it would in C #. Therefore, it should look like this:

generic <typename T>
where T: MyFetch, gcnew()
IEnumerable<T>^ Fetch() {
   // etc...
}
+3
source

This will be a common function in yours ref classand will look something like this:

generic <typename T>
where T: MyFetch, gcnew()
IEnumerable<T>^ Fetch() 
{
}
+3
source

All Articles