c++ cli - Unable to use dynamic_cast with generics -
i have generic class client
has single type parameter. type parameter reference type derived base
. declare class below:
generic <class t> t : base, gcnew() public ref class client { t val; void setval(base ^bval){ val = dynamic_cast<t>(bval); // error c2682: cannot use 'dynamic_cast' convert 'base ^' 't' } };
why compile error when using dynamic_cast
convert base
1 of derived classes? expecting cast compile fail @ runtime (by returning nullptr
) in case argument of incorrect type.
try dynamic_cast <t^>
.
pointers have cast other pointers, handles other handles, , forth.
Comments
Post a Comment