example2_glvalues_in_expressions.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <iostream>

int getValue() {
    int a = 42;
    return a;
}

int main() {
    int&& r = getValue();  // getValue() is a prvalue, but r is an xvalue (and hence a glvalue)
    
    std::cout << r << std::endl;  // 'r' is a glvalue

    r = 100;  // Modifies the temporary that was returned by getValue()

    std::cout << r << std::endl;  // 'r' is still a glvalue

    return 0;
}
Back to glvalue