marczellm
marczellm

Reputation: 1336

Declare pointer to 2D enum array

Consider the MNWE:

enum T {VALUE};

int main() {
    T T_arr[8][8];
    T** T_arr_ptr = T_arr;
}

Now this does not compile, saying

error: cannot convert T(*)[8] to T** in initialization

Without using auto, what would be the correct type for this pointer?

Upvotes: 1

Views: 417

Answers (1)

haccks
haccks

Reputation: 106012

2D array names decays to pointer to first row of the array and hence it is of type pointer to array. Here T_arr is of type T(*)[8] after decay.
Change

T** T_arr_ptr = T_arr;  

to

T (*T_arr_ptr)[8] = T_arr;

Upvotes: 1

Related Questions