How to get around the warning “rvalue used as lvalue”?

蹲街弑〆低调 提交于 2019-12-19 06:18:47

问题


I'm using this tutorial, but when I compile the code from it:

D3DXMatrixLookAtLH(
    &matView,
    &D3DXVECTOR3(0.0f, 10.0f, 0.0f), // warning C4238
    &D3DXVECTOR3(0.0f, 0.0f, 0.0f), // warning C4238
    &D3DXVECTOR3(0.0f, 0.0f, 1.0f) // warning C4238
);

I get:

warning C4238: nonstandard extension used : class rvalue used as lvalue

What is the proper (warningless) way of doing this without additional lines of code?

Also, I'm wondering what is so bad about that line of code? Why does it even give warning if it works just fine? Or does it...?


回答1:


You are taking the address of a temporary. You can't do that. Declare your vectors beforehand:

D3DXVECTOR3 a(0.0f, 10.0f, 0.0f)
            ,b(0.0f, 0.0f, 0.0f)
            ,c(0.0f, 0.0f, 1.0f);
D3DXMatrixLookAtLH(&matView, &a, &b, &c);

Note that I ignored your "without additional lines of code?" requirement, because that's a stupid requirement.



来源:https://stackoverflow.com/questions/8763043/how-to-get-around-the-warning-rvalue-used-as-lvalue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!