Generic class for value type : Generic Class « Generics « Visual C++ .NET






Generic class for value type

 
#include "stdafx.h"
using namespace System;

generic <typename T>
ref class GenericClass
{
   T t;

   public:

      GenericClass() {}

      property T InnerValue
      {
          T get() { return t; }
          void set(T value) { t = value; }
      }
};

int main()
{
   double d = 0.01;
   int n = 12;

   GenericClass<double>^ r_double = gcnew GenericClass<double>();

   GenericClass<int>^ r_int = gcnew GenericClass<int>();

   r_double->InnerValue = d;

   r_int->InnerValue = n;

   Console::WriteLine( r_double->InnerValue );

   Console::WriteLine( r_int->InnerValue );
}

   
  








Related examples in the same category

1.Generic Class Demo
2.Generic class definition