Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
387 views
in Technique[技术] by (71.8m points)

c++ - What is the value category of string literals?

I'm pretty sure the value category of integer, character, boolean and floating point literals is prvalue.

User defined literals are like function calls, so their value category depends on the return type of the operator function they resolve to.

I'm not clear on string literals. They have type "array of const charx" where charx is some character type.

It says in 3.10:

The value of a literal ... is also a prvalue.

But I think this might not apply to string literals?

What is the value category of a string literal? How did you determine this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

So I'm pretty sure the value category of integer, character, boolean and floating literals are prvalues.

That's correct.

What is the value category of a string literal?

Per Paragraph 5.1.1/1 of the C++11 Standard:

A literal is a primary expression. Its type depends on its form (2.14). A string literal is an lvalue; all other literals are prvalues.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...