.net - Selecting overload with tracking reference -
in c#, can have code following:
void add(vector3 a, vector3 b, out vector3 c) { add(ref a, ref b, out c); } void add(ref vector3 a, ref vector3 b, out vector3 c) { c.x = a.x + b.x; c.y = a.y + b.y; c.z = a.z + b.z; }
however, in c++/cli, compiler (understandably) not able select correct overload:
void add(vector3 a, vector3 b, [out] vector3% c) { add(a, b, c); } void add(vector3% a, vector3% b, [out] vector3% c) { c.x = a.x + b.x; c.y = a.y + b.y; c.z = a.z + b.z; }
how indicate compiler want select second overload?
as hans passant said in comment post, not possible. point of value types should small enough efficient copy, , if aren't, should not value types. there therefore no need second overload in cases.
edit: hans said not true. generates (almost) exact same il c# version (the difference adds modopt([mscorlib]system.runtime.compilerservices.isexplicitlydereferenced)
):
void add(vector3 a, vector3 b, [out] vector3% c) { add(&a, &b, c); } void add(interior_ptr<vector3> a, interior_ptr<vector3> b, [out] vector3% c) { c.x = a->x + b->x; c.y = a->y + b->y; c.z = a->z + b->z; }
Comments
Post a Comment