C++ type casting vector class
I have two vector classes:
typedef struct D3DXVECTOR3 {
FLOAT x;
FLOAT y;
FLOAT z;
} D3DXVECTOR3, *LPD3DXVECTOR3;
and
class MyVector3{
FLOAT x;
FLOAT y;
FLOAT z;
};
and a function:
void funct开发者_如何学Cion(D3DXVECTOR3* Vector);
How is it possible (if it's possible) to achieve something like this:
MyVector3 vTest;
function(&vTest);
function(reinterpret_cast<D3DXVECTOR3*>(&vTest));
Generally speaking you should avoid reinterpret_cast
though.
Looks like you want a wrapper class for D3DXVECTOR3. In this case just inherit MyVector3 from it. Then you can pass MyVector3* anywhere you could earlier pass D3DXVECTOR3*.
old c-style cast
MyVector3 vTest;
function((D3DXVECTOR3*)&vTest);
精彩评论