c++ - 如何显式编写数组引用返回类型?

标签 c++ syntax

<分区>

我想知道如何明确返回数组引用的函数的返回类型。

typedef int const (Three_Const_Ints)[3];

Three_Const_Ints const & foo ()
{
    static int const values[] = { 0, 1, 2 };
    return values;
}

int const (&)[3] bar ()   // Does not compile. What is the proper syntax?
{
    static int const values[] = { 0, 1, 2 };
    return values;
}

是的,我可以使用 std::array,但我想知道它的语法。

最佳答案

它是这样的:

int const (&bar())[3];

关于c++ - 如何显式编写数组引用返回类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25169021/

相关文章:

c++ - 使用 SDDL 或手动创建安全描述符之间的区别?

c++ - 使用 std::dynamic_pointer_cast 向上转换 std::shared_ptr

c++ - QMediaPlayer:发出 positionChanged() 时声音中断

c++ - 记录在一行中声明的成员而不创建组

python - 为什么需要用括号括起一个整数来调用它的方法?

c# - 为什么 C# 允许没有前置语句的 {} 代码块?

python - Python无效语法为何?c

c++ - 使用集合对 vector 进行排序

Jquery 终端文本格式化语法,我做错了什么?

PHP MySql INSERT INTO - 语法错误