views:

247

answers:

3

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);
+2  A: 
function(reinterpret_cast<D3DXVECTOR3*>(&vTest));

Generally speaking you should avoid reinterpret_cast though.

Andreas Brinck
+1  A: 

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*.

sharptooth
+1  A: 

old c-style cast

MyVector3 vTest;
function((D3DXVECTOR3*)&vTest);
Diaa Sami