c++ - 字符串文字的值类别是什么?

标签 c++ c++11

我很确定整数、字符、 bool 值和浮点文字的值类别是纯右值。

用户定义的文字就像函数调用,因此它们的值类别取决于它们解析为的运算符函数的返回类型。

我不清楚字符串文字。它们的类型为“array of const charx”,其中 charx 是某种字符类型。

它在 3.10 中说:

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

但我认为这可能不适用于字符串文字?

字符串文字的值类别是什么?你是如何确定的?

最佳答案

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

没错。

What is the value category of a string literal?

根据 C++11 标准的第 5.1.1/1 段:

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.

关于c++ - 字符串文字的值类别是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15036281/

相关文章:

c++11 - std::numeric_limits::quiet_NaN() 与 std::nan() 与 NAN

c++ - dlclose() 不适用于工厂函数和函数中的复杂静态?

C++ std::function 返回它自己类型的 vector (再次递归类型)

c++ - GLEW 编译,但在运行时崩溃

c++ - 为什么我可以将接受值的可调用对象传递给接受引用的 std::function?

c++ - type_traits 中是否有类似 std::remove_const_reference 的东西

c++ - 为什么叫运算符重载呢?

c++ - QScrollArea 不能按预期与 QWidget 和 QVBoxLayout 一起工作

c++ - 将固定长度的字符数组分配给字符串

c++ - Printf Fprintf 输出顺序