&D3DXVECTOR3 causes error C2102 '&' requires l-value

543 views Asked by At

first time here. Im trying to move the .png file using direct3d 9 function: &D3DXVECTOR3 but when I run local windows debugger it shows '&' require l-value error. I tried to search for similar case using direct3d9 but I found nothing. I would like to know what is the cause of the error and how could I fix it.

sprite->Draw(pointer, NULL, NULL, &D3DXVECTOR3(32, 32, 0), D3DCOLOR_XRGB(255, 255, 255));

I use NULL instead of D3DXVECTOR3 at first and it runs perfectly but when change to D3DXVECTOR3 it shows the error.

1

There are 1 answers

0
Chuck Walbourn On

Taking the address of a temporary object like this is not C++ standard conformant.

Microsoft Visual C++ has historically accepted this usage as a "language extension", and it still does unless you are building with /permissive- (i.e. Conformance Mode) enabled. Without /permissive-, at Warning Level 4 it still emits a C4238 warning.

clang/LLVM for Windows will also accept this usage, but outputs a -Waddress-of-temporary warning.

The conformant solution is to create a named temporary:

D3DXVECTOR3 v(32, 32, 0);
sprite->Draw(pointer, NULL, NULL, &v, D3DCOLOR_XRGB(255, 255, 255));

You should note that you are using legacy Direct3D 9, the deprecated D3DX9 library, and the deprecated D3DXMath library. See Microsoft Docs. These days, the recommendation is to use Direct3D 11, DirectXMath, and the DirectX Tool Kit SpriteBatch instead.