Returning an array of links from a const member function

How to return an array reference from a const function?

class State{
    Chips (&arr() const)[6][7] { return arr_; }
    Chips val() const { return val_; }
}

Incorrect initialization of a link of type 'Chips (&) [6] [7]' from an expression of type 'const Chips [6] [7]'

Thank.

+3
source share
2 answers

, arr_ (, , ), . arr arr_ const Chips[6][7]. Chops (&)[6][7], const-correctness. , , const

...
const Chips (&arr() const)[6][7] { return arr_; }
...

typedef

...
typedef Chips Chips67[6][7];
const Chips67 &arr() const { return arr_; }
...
+7

. ,

Chips* arr() const;

, .

-2

Source: https://habr.com/ru/post/1765030/


All Articles