lvalue

Why are arrays not lvalues? [duplicate]

橙三吉。 提交于 2021-02-07 20:21:05
问题 This question already has answers here : Why array type object is not modifiable? (5 answers) Closed 6 years ago . I understand that the C standard prohibits the use of arrays as (modifiable) lvalues, that is, on the left-hand side of an assignment: int lhs[4], rhs[4] = {0, 1, 2, 3}; lhs = rhs; /* illegal! */ Now, I have been wondering why this is the case. I could see the statement above (and any other assignment that writes to an array) being defined equivalent to memcpy((void *) lhs, (void

Since a string literal is considered an lvalue, why must the binding lvalue reference be const?

醉酒当歌 提交于 2021-02-07 05:10:51
问题 I know there are topics that are similar to this one already (such as this). The example given in this topic was this: std::string & rs1 = std::string(); Clearly, that std::string() is an rvalue. However, my question is why is s1 legal while s2 is not? const std::string& s1 = "String literal"; std::string& s2 = "String literal"; The standard clearly states that string literals are lvalues (which is understandable since they are technically const char* behind the scenes). When I compile s2

Since a string literal is considered an lvalue, why must the binding lvalue reference be const?

▼魔方 西西 提交于 2021-02-07 05:08:53
问题 I know there are topics that are similar to this one already (such as this). The example given in this topic was this: std::string & rs1 = std::string(); Clearly, that std::string() is an rvalue. However, my question is why is s1 legal while s2 is not? const std::string& s1 = "String literal"; std::string& s2 = "String literal"; The standard clearly states that string literals are lvalues (which is understandable since they are technically const char* behind the scenes). When I compile s2

Since a string literal is considered an lvalue, why must the binding lvalue reference be const?

天大地大妈咪最大 提交于 2021-02-07 05:05:11
问题 I know there are topics that are similar to this one already (such as this). The example given in this topic was this: std::string & rs1 = std::string(); Clearly, that std::string() is an rvalue. However, my question is why is s1 legal while s2 is not? const std::string& s1 = "String literal"; std::string& s2 = "String literal"; The standard clearly states that string literals are lvalues (which is understandable since they are technically const char* behind the scenes). When I compile s2

Since a string literal is considered an lvalue, why must the binding lvalue reference be const?

对着背影说爱祢 提交于 2021-02-07 05:05:02
问题 I know there are topics that are similar to this one already (such as this). The example given in this topic was this: std::string & rs1 = std::string(); Clearly, that std::string() is an rvalue. However, my question is why is s1 legal while s2 is not? const std::string& s1 = "String literal"; std::string& s2 = "String literal"; The standard clearly states that string literals are lvalues (which is understandable since they are technically const char* behind the scenes). When I compile s2

What rules are there for qualifiers of effective type?

不想你离开。 提交于 2021-01-28 11:32:51
问题 So I was re-reading C17 6.5/6 - 6.5/7 regarding effective type and strict aliasing, but couldn't figure out how to treat qualifiers. Some things confuse me: I always assumed that qualifiers aren't really relevant for effective type since the rules speak of lvalue access, meaning lvalue conversion that discards qualifiers. But what if the object is a pointer? Qualifiers to the pointed-at data aren't affected by lvalue conversion. Q1: What if the effective type is a pointer to qualified-type?

Pass lvalue to rvalue

谁说我不能喝 提交于 2021-01-21 07:16:48
问题 I made a small 'blocking queue' class. It irritates me that I have created redundant code for values passed into the enqueue member function. Here are the two functions that do the same exact thing (except the rvalue uses std::move to move the rvalue into the actual queue collection), except handles lvalue and rvalue respectively: void enqueue(const T& item) { std::unique_lock<std::mutex> lock(m); this->push(item); this->data_available = true; cv.notify_one(); } void enqueue(T&& item) { std:

Why doesn't a+++++b work?

故事扮演 提交于 2020-02-13 04:07:00
问题 int main () { int a = 5,b = 2; printf("%d",a+++++b); return 0; } This code gives the following error: error: lvalue required as increment operand But if I put spaces throughout a++ + and ++b , then it works fine. int main () { int a = 5,b = 2; printf("%d",a++ + ++b); return 0; } What does the error mean in the first example? 回答1: printf("%d",a+++++b); is interpreted as (a++)++ + b according to the Maximal Munch Rule ! . ++ (postfix) doesn't evaluate to an lvalue but it requires its operand to

function template does not recognize lvalue

我的梦境 提交于 2020-02-03 05:48:25
问题 I have a problem in my code Here is simplified version of it : #include <iostream> class A { public : template <class T> void func(T&&)//accept rvalue { std::cout<<"in rvalue\n"; } template <class T> void func(const T&)//accept lvalue { std::cout<<"in lvalue\n"; } }; int main() { A a; double n=3; a.func(n); a.func(5); } I expect the output to be : in lvalue in rvalue but it is in rvalue in rvalue why ?! 回答1: template <class T> void func(T&&) is universal reference forwarding reference . To