Mega Code Archive

 
Categories / Visual C++ .NET / Generics
 

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()); }