reflection - Native types and Generics -
i want create native array , access managed code. don't want re write code different types, (int
, long
, float
, double
) therefore tried using generics.
typedef int ind; generic <typename t> public ref class ntvarray { void *pnt; ind sz; public: ntvarray(ind length) { sz = sizeof(t); pnt = ::operator new(length*sz); } ~ntvarray() { ::operator delete(pnt); } void* pointer() { return pnt; } t getitem (ind index) { //c3229 return ((t*)pnt)[index]; } void setitem (ind index, t value) { //c3229 ((t*)pnt)[index] = value; } };
i getting error , know reason error,
error c3229:
't *'
: indirections on generic type parameter not allowed
however there way using generics? other way this, may else other using generics?
no, can't using generics. can use templates. avoids code duplication, question emphasizes, won't allow run-time instantiation generics would.
Comments
Post a Comment