example3_prvalues_and_temporary_objects.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#include <iostream>
#include <string>

std::string createString() {
    return "Temporary String";  // The string literal is a prvalue
}

int main() {
    std::string str = createString();  // The returned string is a prvalue

    std::cout << "str: " << str << std::endl;

    return 0;
}
Back to prvalue