“所需的I值”错误 [英] "l-value required" error

查看:193
本文介绍了“所需的I值”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当编译C ++程序时,我们得到需要l值错误(我使用VC ++)

When do we get "l-value required" error...while compiling C++ program???(i am using VC++ )

推荐答案

lvalue是可以作为赋值目标的值。 l代表左,如在等号的左手边。右值是右边的值,产生一个值,不能直接赋值。如果你得到需要lvalue,你有一个表达式,当需要左值时产生右值。

An "lvalue" is a value that can be the target of an assignment. The "l" stands for "left", as in the left hand side of the equals sign. An rvalue is the right hand value and produces a value, and cannot be assigned to directly. If you are getting "lvalue required" you have an expression that produces an rvalue when an lvalue is required.

例如,一个常数是一个右值,而不是一个左值。所以:

For example, a constant is an rvalue but not an lvalue. So:

1 = 2;  // Not well formed, assigning to an rvalue
int i; (i + 1) = 2;  // Not well formed, assigning to an rvalue.

不起作用,但是:

int i;
i = 2;

注意,你可以从函数返回一个左值;例如,您可以返回对提供operator =()的对象的引用。

Does. Note that you can return an lvalue from a function; for example, you can return a reference to an object that provides a operator=().

正如Pavel Minaev在注释中指出的,这不是一个正式的定义左值和右值,但尝试给某人的描述困惑了关于使用右值需要左值的错误。 C ++是一种具有许多细节的语言;如果你想获得正式的,你应该参考一个正式的参考。

As pointed out by Pavel Minaev in comments, this is not a formal definition of lvalues and rvalues in the language, but attempts to give a description to someone confused about an error about using an rvalue where an lvalue is required. C++ is a language with many details; if you want to get formal you should consult a formal reference.

这篇关于“所需的I值”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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