- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
首先,我认为它是一个右值
,但下面的事实改变了我的想法。
我尝试了一个表达式 &(*&a)
并且它工作正常,但是运算符 &
只能使用 lvalue
,所以 (*&a)
是一个 lvalue
,为什么?
最佳答案
根据 C 2018 6.5.3.2 4(讨论 unary *
运算符),一元 *
的结果是一个左值:
… If the operand points to a function, the result is a function designator; if it points to an object, the result is an lvalue designating the object.…
这告诉我们 *&a
是一个左值。但是题中问到的表达式是(*&a)
,所以要考虑括号的作用。
6.3.2.1 2(讨论自动转换)似乎告诉我们 (*&a)
被转换为 *&a
中的值而不是左值:
Except when it is the operand of the sizeof operator, the unary
&
operator, the++
operator, the--
operator, or the left operand of the.
operator or an assignment operator, an lvalue that does not have array type is converted to the value stored in the designated object (and is no longer an lvalue); this is called lvalue conversion.
但是,6.5.1 5(讨论带括号的表达式)与此矛盾:
A parenthesized expression is a primary expression. Its type and value are identical to those of the unparenthesized expression. It is an lvalue, a function designator, or a void expression if the unparenthesized expression is, respectively, an lvalue, a function designator, or a void expression.
这是C标准的缺陷; 6.5.1 5 和 6.3.2.1 2 相互矛盾。留给我们理解的是 6.5.1 5,它专门关于括号表达式,优先于更一般的 6.3.2.1 2,这就是所有 C 实现的行为方式。
因此 (*&a)
是一个左值。
关于c - (*&) 是左值还是 r 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57691619/
我是 C++ 的新手,正在尝试编写如下接口(interface): template class Comparable { protected: Comparable(){};
什么是左值? 最佳答案 左值是可以分配给以下值的值: lvalue = rvalue; 它是“left value”或“lefthand value”的缩写,它基本上只是=符号左侧的值,即您为其分配值
这个问题已经有答案了: Why do C and C++ support memberwise assignment of arrays within structs, but not general
C++03 $14.1/6 - "A non-type non-reference template-parameter is not an lvalue." C++0x $14.2/6- "A no
这只是出于好奇我问... 我在任何地方看到的 99% 的代码,当使用“IF”时,将采用“If (RValue == LValue) ...”格式。例子: If (variableABC == "Hel
在 C++03 中,表达式可以是右值,也可以是左值。 在 C++11 中,表达式可以是: 右值 左值 x值 gl值 右值 两个类别变成了五个类别。 这些新的表达类别是什么? 这些新类别与现有的右值和左
我正在尝试将 div 向左移动指定数量的像素,我正在使用从此处获得的 slider : http://carpe.ambiprospect.com/slider/archive/v1.3/ 所以从示例
所以我有一个函数需要将 std::vector 作为参数。我想知道声明参数的最佳方式,这样底层数组就不会被深度复制,因为它可能相当大。 // which should I choose? void m
在 C++03 中,表达式要么是右值,要么是左值。 在 C++11 中,表达式可以是: 右值 左值 xvalue glvalue 右值 两类变成了五类。 这些新的表达类别是什么? 这些新类别与现有的右
我正在尝试实现类似 find 的方法来从容器中提取对值的引用,如果找不到该值或该值的类型不兼容,则返回一个默认值。 template const T& get (key_type k, const T
我有以下代码: #include using namespace std; void test(int& a) { cout << "lvalue." << endl; } void tes
我的搜索发现许多关于右值绑定(bind)到左值的帖子,但没有任何类似的帖子。对不起,如果它是重复的。 struct StrHolder { StrHolder(std::string&& s)
这是一个后续问题 C++0x rvalue references and temporaries 在上一个问题中,我问过这段代码应该如何工作: void f(const std::string &);
为什么这不起作用: ostream& operator' lvalue to 'std::basic_ostream&&'| error: initializing argument 1 of '
偶尔,我被问到一个技巧问题:x++ 和 ++x 哪个不能在 c 中留值?很多人告诉我++x不能,因为++x的汇编代码不返回寄存器。我对此表示怀疑。所以我做了一些实验。 C 代码: #include
所以这个问题与我为实际问题选择的解决方案有关,为了尽可能提供完整的图片,这个问题是这样的:基本上我有一个带有很多模板参数的函数,我正在尝试暴露给 Python。与用宏做一些噩梦般的事情来消除我需要的所
指针很简单。有一些内存保存着一个地址。要获得(有意义的)值,取消引用返回地址指向的内存中包含的值。 引用以某种方式做一些类似的事情:它们持有指向一个临时对象的“链接”。但是当我分配或使用引用时会发生什
下面是一些示例代码: #include class Foo { public: explicit Foo(int x) : data(x) {}; Foo& operator++() {
背景 以下代码块出现在 Scott Meyers 的名著 "Effective C++" 中第 3 项: class TextBlock { public: ... const cha
我是一名优秀的程序员,十分优秀!