Gilgamesz
Gilgamesz

Reputation: 5073

What is value type of *T?

Let's consider very short piece of code in C++:

class T{
};
T *t = new T();

What is type of *t? rvalue/lvalue/xvalue/glvalue? why? Thanks in advance.

Upvotes: 0

Views: 58

Answers (1)

R Sahu
R Sahu

Reputation: 206717

The check for lvalue is very simple. Can it appear on the left hand side of an assignment operator?

In your case, the answer is "yes".

*t = T();

is valid. Hence, the value of type of *t is lvalue.

By virtue of being an lvalue, it is also a glvalue.

From https://timsong-cpp.github.io/cppwp/n3337/basic.lval:

A glvalue (“generalized” lvalue) is an lvalue or an xvalue.

Upvotes: 1

Related Questions