Generic function and generic array : Generic Function « Generics « Visual C++ .NET






Generic function and generic array

 

#include "stdafx.h"
using namespace System;

generic < typename T>
void GenericFunction(array<T>^ array_of_t)
{
   for each (T t in array_of_t)
   {
      Console::WriteLine(t);
   }
}

int main()
{
   array<String^>^ array_of_string;

   array_of_string = gcnew array<String^>{ "abc", "def", "ghi" };

   GenericFunction( array_of_string );
}

   
  








Related examples in the same category

1.Generic function demo
2.Generic function allows the type parameter to be deduced
3.generic multiple constraints
4.generic return value
5.Specify the type parameter for generic function