interface constraint : Generic Interface « Generics « Visual C++ .NET






interface constraint

 
#include "stdafx.h"
interface class I
{
    void f();
};

generic <typename T> where T : I
ref class MyGenericClass
{
    T t;

    public:
       MyGenericClass(T t_in) : t(t_in)
       {
           t->f();
       }
};

ref class C : I
{
   public:
       virtual void f()
       {
       }
};

int main()
{
     MyGenericClass<C^>^ r = gcnew MyGenericClass<C^>(gcnew C());
}

   
  








Related examples in the same category

1.generic interface demo
2.interface with overloaded operator