this is what i mean,
class V3
{
public:
float x,y,z;
};
class V3_
{
public:
float x,y,z;
};
V3_ vec1;
V3 vec2 = static_cast<V3_>(vec1);
what should i do to make this cast work in compile time?
Thanks.
edit:
there seems to be some misunderstanding about what i want to do.
i can write an operator to the conversion, but i want it to be done in compile time.
here are two implementations of Vector3 that allows static_cast. i dont know how does it work, but it does work.
http://www.ogre3d.org/docs/api/html/OgreVector3_8h_source.html
http://harry-3d-engine.googlecode.com/svn/trunk/NxOgreVec3.h
i can do this cast
void DynamicBody::SetLinearMomentum(const Vector3& vel)
{
body->setLinearMomentum(static_cast<NxOgre::Vec3>(vel));
}
i would like an explanation on how i can do this.
edit:
upon further investigation i found how it actually does this,
it calls
template<class user_xyz_vector_type>
inline user_xyz_vector_type as() const { ... }
that is not an actual static_cast, but compiler accepts it as one.
i really hoped casting pods to eachother was an actual thing.
This cast will not work at any time. You can’t
static_castcompletely unrelated and not convertible types to each other.I’m not sure what you are trying to do, so I don’t know what the work “work” means in this case, but at a raw memory level the conversion can be performed by
reinterpret_castbut this is an ugly hack that is not guaranteed to work, since, again, your types are unrelated. With the same degree (or even better) of success you can simply
memcpyone object into another.