In C++, what categories (lvalue, rvalue, xvalue, etc.) can expressions that produce temporaries of class type fall into?

前端 未结 2 1067
孤街浪徒
孤街浪徒 2020-11-27 06:23

Here is some example code:

#include 

class Foo
{
public:
  explicit Foo(int x) : data(x) {};

  Foo& operator++()
  {
    data += 1;
            


        
2条回答
  •  广开言路
    2020-11-27 07:00

    Any expression in C++ is either an lvalue or an rvalue. Hence, you're asking for the classifications that are rvalues. For that, inspect the figure showing the tree of classifications, in the C++11 standard §3.10/1.

    Expression category taxonomy


    For more info (without delving into the standard) see What are rvalues, lvalues, ....


    Regarding

    “Are expressions like Foo(5) rvalues or prvalue”

    a prvalue is necessary an rvalue – for it couldn't very well be an lvalue.

    A prvalue “(“pure” rvalue) is an rvalue that is not an xvalue”, and an xvalue is “the result of certain kinds of expressions involving rvalue references” A constructor call does not produce an rvalue reference, hence it's not an xvalue. So the rvalue is a prvalue, a pure rvalue.

提交回复
热议问题