Consider the following code:
#include <iostream> using namespace std; class X { int i; public: X(int ii = 0); }; X::X(int ii) { i = ii; } int a; X f1() { return X(); } int f2() { return a; } int main() { f1() = X(1); f2() = 3; }
If you try to run it, you will get
error: lvalue required as left assignment operand
on line 17, therefore
f1 ()
considered lvalue, and
2 ()
no. An explanation will be of great help in how this will work.
f1() considered lvalue
f1()
, , f1, rvalue ( , f2, prvalue). f1() = X(1); f1().operator=(X(1));, , ; , f1(), . , - rvalue .
f1
f2
f1() = X(1);
f1().operator=(X(1));
, ; . , lvalue.
f1() rvalue. (lvalue),
int f2() { return a; }
int& f2() { return a; } ^
f1() rvalue, f1() = X(1); f1().operator=(X(1));, .
.
Source: https://habr.com/ru/post/1684528/More articles:Partial controller with various attributes in ASP.NET MVC - c #Более элегантный способ совпадения после значения HashMap, чем клонирование - cachingHow is "+ & r" different from "+ r"? - cWPF Multibinding not working - shortcuts empty - c #Catch youtube embeds video events in ionic 3 app - youtubeThreepenny-GUI: Drag'n'Drop - access to DragData - haskellpass and lambdas parameter for C # extension method in F # - c #Преобразование плоского массива объектов в вложенные объекты - jsonElm: How to define a function that executes a query with a message as a parameter - elmhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1684533/android-notification-returns-to-the-wrong-activity&usg=ALkJrhiiTUE1MWbLB0phpRkjb8tpfRTMUQAll Articles