开发者

C++ type casting vector class

开发者 https://www.devze.com 2022-12-13 10:20 出处:网络
I have two vector classes: typedef struct D3DXVECTOR3 { FLOAT x; FLOAT y; FLOAT z; } D3DXVECTOR3, *LPD3DXVECTOR3;

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消