C++ type casting vector class

ccastingtypesvector

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 function(D3DXVECTOR3* Vector);

How is it possible (if it's possible) to achieve something like this:

MyVector3 vTest;
function(&vTest);

Best Answer

function(reinterpret_cast<D3DXVECTOR3*>(&vTest));

Generally speaking you should avoid reinterpret_cast though.