如何显式编写数组引用返回类型? [重复]

问题描述 投票:0回答:3

SO是一场狗屎秀。感谢您的搭车。

c++ syntax
3个回答
1
投票

事情是这样的:

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

1
投票

要返回对数组的引用,请使用以下语法:

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

0
投票

尝试以下方法

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

或者

typedef const int Three_Const_Ints[3];

Three_Const_Ints & f()
{
    static Three_Const_Ints values = { 0, 1, 2 };
    return values;
}
© www.soinside.com 2019 - 2024. All rights reserved.