What is an lvalue?

Possible Duplicate: What are rvalues, lvalues, xvalues, glvalues, and prvalues? The C++ Standard, mostly in Chapter 5, entitled Expressions, defines which expressions are lvalues and which are rvalues. I have read that chapter, and I believe I can correctly distinguish between lvalues and rvalues. However before I had read good C++ books and/or the standard, I used to think that an lvalue

什么是左值?

可能重复: 什么是右值,左值,xvalues,glvalues和prvalues? 主要在第5章标题为“表达式”的C ++标准定义了哪些表达式是左值和哪些是右值。 我已阅读过这一章,我相信我能正确区分左值和右值。 然而,在我阅读完善的C ++书籍和/或标准之前,我曾经认为左值是可以站在赋值左侧的东西,而右值是不能的。 很明显,这个幼稚的定义有很多反例。 一段时间后,我认为左值是有地址的东西,右值是没有的地址。 这也似乎以一些临

Xvalues vs prvalues: what does identity property add

I'm sorry for the broadness of the question, it's just that all these details are tightly interconnected.. I've been trying to understand the difference between specifically two value categories - xvalues and prvalues, but still I'm confused. The property of having identity (which makes xvalue different from prvalue) is discussed in the following question on SO: Is it correc

Xvalues与prvalues:身份属性添加了什么

对于问题的广泛性,我感到抱歉,只是所有这些细节都紧密相关。 我一直试图理解具体的两个值类别 - xvalues和prvalues之间的区别,但我仍然感到困惑。 具有身份(使得x值与prvalue不同)的属性在SO上的以下问题中讨论: 说xvalues具有身份并且可移动是否正确? 首先,被接受的答案引用了关于xvalue定义的§5/ 7; cppreference(http://en.cppreference.com/w/cpp/language/value_category)提供了一个更广泛的xvalue定义

Aren't xvalues both glvalues and rvalues?

I read this answer the part that caught my attention was this: int i; int* p = &i; int& f(); int&& g(); int h(); h() // prvalue g() // glvalue (xvalue) f() // glvalue (lvalue) i // glvalue (lvalue) *p // glvalue (lvalue) std::move(i) // glvalue (xvalue) and with this chart in mind I got confused. If a glvalue is either an lvalue or an xvalue and an rvalue is either a

不是xvalues既是glvalues又rvalues?

我读到这个答案引起了我的注意的部分是这样的: int i; int* p = &i; int& f(); int&& g(); int h(); h() // prvalue g() // glvalue (xvalue) f() // glvalue (lvalue) i // glvalue (lvalue) *p // glvalue (lvalue) std::move(i) // glvalue (xvalue) 并考虑到这个图表 我很困惑。 如果一个glvalue是一个左值或一个xvalue,并且一个右值是一个prvalue或者一个xvalue,那么说g()是一个glvalue并

lvalue to rvalue implicit conversion

I see the term "lvalue-to-rvalue conversion" used in many places throughout the C++ standard. This kind of conversion is often done implicitly, as far as I can tell. One unexpected (to me) feature of the phrasing from the standard is that they decide to treat lvalue-to-rvalue as a conversion. What if they had said that a glvalue is always acceptable instead of a prvalue. Would that

左值到右值的隐式转换

我在整个C ++标准的许多地方看到术语“左值到右值的转换”。 就我所知,这种转换通常是隐含的。 标准中措辞的一个意想不到的(对我来说)特征是他们决定将左值转换为右值作为转换。 如果他们说过一个总是可以接受的而不是一个价值的话,那该怎么办? 那个短语实际上会有不同的含义吗? 例如,我们读到左值和x值是glvalues的例子。 我们没有看到左值和右值可以转换为glvalues。 意义有什么不同? 在我第一次遇到这个术语

xvalue's lifetime bound to reference extended or not?

Apparently there is some confusion and differences between compilers as regards this issue: http://social.msdn.microsoft.com/Forums/vstudio/en-US/3c754c4e-5471-4095-afae-795c1f411612/rvalue-refs-extended-lifetime-inconsistent-with-gccstandard According to this post: What are rvalues, lvalues, xvalues, glvalues, and prvalues? Xvalues are rvalues (along with prvalues) and the standard says:

xvalue的生存期限是否延长?

显然,编译器在这个问题上存在一些混淆和区别: http://social.msdn.microsoft.com/Forums/vstudio/en-US/3c754c4e-5471-4095-afae-795c1f411612/rvalue-refs-extended-lifetime-inconsistent-with-gccstandard 根据这篇文章: 什么是右值,左值,xvalues,glvalues和prvalues? Xvalues是rvalues(与prvalues一起),标准说: 第二个上下文是当引用绑定到临时的时候。 引用绑定到的临时对象或引用绑定到的子对象的完

Is there any danger in calling free() or delete instead of delete[]?

Possible Duplicate: ( POD )freeing memory : is delete[] equal to delete ? Does delete deallocate the elements beyond the first in an array? char *s = new char[n]; delete s; Does it matter in the above case seeing as all the elements of s are allocated contiguously, and it shouldn't be possible to delete only a portion of the array? For more complex types, would delete call the destruc

调用free()或删除而不是delete []会有危险吗?

可能重复: (POD)释放内存:是否删除[]等于删除? delete是否释放数组中的第一个元素? char *s = new char[n]; delete s; 在上面的情况下,看到s所有元素是连续分配的,并且不应该只能delete数组的一部分吗? 对于更复杂的类型,会delete调用第一个对象的析构函数吗? Object *p = new Object[n]; delete p; 如何delete[]推断超出第一个Object的数量,是不是这意味着它必须知道分配内存区域的大小? 出于性能方面

When is it appropriate to use static (over unnamed namespaces) in C++?

I have been reading articles about unnamed namespaces the whole day, most articles explained when you should use unnamed namespaces over the static keyword. But I am still left with one big question when is it appropriate to use static? After all it is not completely deprecated, what about header files with static functions should I put them into unnamed namespaces now? #ifndef HEADER_H #defin

什么时候适合在C ++中使用静态(通过未命名的名称空间)?

我一整天都在阅读有关未命名的命名空间的文章,大多数文章都解释了何时应该使用静态关键字的未命名命名空间。 但是,我仍然留下一个很大的问题,何时适合使用静态? 毕竟它还没有被完全弃用,那么现在我应该如何将它们放入未命名的命名空间中,并且使用静态函数的头文件呢? #ifndef HEADER_H #define HEADER_H static int func() { ... } // versus: namespace { int func() { ... } }; #endif // HEADER_H

Obtaining a pointer to the end of an array

I use the following template to obtain a pointer pointing after the last element of an array: template <typename T, size_t n> T* end_of(T (&array)[n]) { return array + n; } Now I seem to remember that there was some problem with this approach, but I cannot remember what it was. I believe it had something to with the choice of the type parameters or function parameters, but I'

获取指向数组末尾的指针

我使用以下模板来获取指向数组最后一个元素的指针: template <typename T, size_t n> T* end_of(T (&array)[n]) { return array + n; } 现在我似乎记得这种方法存在一些问题,但我不记得它是什么。 我相信它与选择类型参数或函数参数有关,但我不确定。 所以,就像一个完整的检查一样,你是否发现上述代码有问题? 小使用测试: int test[] = {11, 19, 5, 17, 7, 3, 13, 2}; std::sort(test, end_of(test));

How are C++ array members handled in copy control functions?

This is something I have wondered for a long time. Take the following example: struct matrix { float data[16]; }; I know what the default constructor and destructor do in this specific example (nothing), but what about the copy constructor and the copy assignment operator? struct matrix { float data[16]; // automatically generated copy constructor matrix(const matrix& tha

如何在复制控制函数中处理C ++数组成员?

这是我长久以来想知道的。 以下面的例子: struct matrix { float data[16]; }; 我知道默认构造函数和析构函数在这个具体例子中做了什么(没有),但是复制构造函数和复制赋值运算符呢? struct matrix { float data[16]; // automatically generated copy constructor matrix(const matrix& that) : // What happens here? { // (or here?) } // automatically generated copy as

May I take the address of the one

Possible Duplicate: Take the address of a one-past-the-end array element via subscript: legal by the C++ Standard or not? int array[10]; int* a = array + 10; // well-defined int* b = &array[10]; // not sure... Is the last line valid or not? Yes, you can take the address one beyond the end of an array, but you can't dereference it. For your array of 10 items, array+10 would wor

我可以看看那个地址吗?

可能重复: 通过C ++标准,通过下标:合法或不合法的方式获取一个最后一个数组元素的地址? int array[10]; int* a = array + 10; // well-defined int* b = &array[10]; // not sure... 最后一行是否有效? 是的,您可以将地址放在数组的末尾,但不能对其进行解引用。 对于10个物品的array+10 , array+10将起作用。 几次(由委员会等人)争论是否&array[10]真的会导致不确定的行为(如果确实如此,是否真