I've got more confused when I see this question: Is a class instantiation--class_name() a xvalue or a prvalue? I'm trying to understand what does it mean by a class prvalue and a class xvalue. Someone tell me that they're called value category. But I think it would be better if I provide an example, because I'm very confused.
class myclass { public: myclass() {}; };
void myfunc(myclass c1){ }
int main(void)
{
myfunc(myclass());
}
So what's myclass()? Is it a prvalue or xvalue?
I need a rule from the standard so that I wouldn't ask more questions.
The expression
myclass()is explicit type conversion using functional notation, per [expr.type.conv]/1:Here, the simple-type-specifier
myclassis followed by parenthesized expression-list()with an empty initializer-list. This expression constructs a value of typemyclassfrom the empty initializer-list.So you might ask, Is that constructed value is prvalue or xvalue or lvalue. So here we've to invoke the immediately next paragraph: [expr.type.conv]/2:
Our initializer is empty initializer-list, and the type is not
cv void, so we've ended with the sentence that says:Hence, the expression
myclass()is a prvalue, whose result object is direct-initialized, from the empty initializer-list, by calling the default constructor.