gufftan
gufftan

Reputation: 173

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

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

MyVector3 vTest;
function(&vTest);

Upvotes: 1

Views: 1599

Answers (3)

Diaa Sami
Diaa Sami

Reputation: 3307

old c-style cast

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

Upvotes: 1

sharptooth
sharptooth

Reputation: 170499

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

Upvotes: 1

Andreas Brinck
Andreas Brinck

Reputation: 52519

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

Generally speaking you should avoid reinterpret_cast though.

Upvotes: 2

Related Questions