如何解决警告“用作左值的右值”? [英] How to get around the warning "rvalue used as lvalue"?

查看:100
本文介绍了如何解决警告“用作左值的右值”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用本教程,但是当我编译来自它的代码:

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

我得到:


警告C4238:使用了非标准扩展名:类rvalue用作左值

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

推荐答案

您正在使用临时地址。你不能那样做。预先声明向量:

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.

这篇关于如何解决警告“用作左值的右值”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆