开发者社区> 问答> 正文

lvalue required as left operand of assignment

关于左值的问题
这样是有问题的d>0?(c+=1):(d?a+=1:b+=1);
这样是没问题的if(d>0)
c+=1;
else if(d)
a+=1;
else
b+=1;
不理解为什么,请大神给好好讲一讲有关左值的问题

展开
收起
a123456678 2016-03-23 10:48:36 5286 0
1 条回答
写回答
取消 提交回答
  • For example, in C, the syntax for a conditional expression is:
    
    logical-OR-expression ? expression : conditional-expression
    while in C++ it is:
    
    logical-OR-expression ? expression : assignment-expression
    Hence, the expression:
    
    e = a < d ? a++ : a = d
    is parsed differently in the two languages. In C, this expression is a syntax error, but many compilers parse it as:
    
    e = ((a < d ? a++ : a) = d)
    which is a semantic error, since th
    
    
    e result of the conditional-expression (which might be a++) is not an lvalue. In C++, it is parsed as:
    
    e = (a < d ? a++ : (a = d))
    which is a valid expression.
    2019-07-17 19:10:29
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Towards A Fault-Tolerant Speaker Verification System: A Regularization Approach To Reduce The Condition Number 立即下载
Froma single droplet toafull b 立即下载
Why you should care about data 立即下载