數組衰減爲指針。在2D陣列的情況下,T[x][y]
類型的數組將衰減到T(*)[y]
,而不是T**
。
§ (8.3.4) Arrays:
If E
is an n-dimensional array of rank i × j × ... × k
, then E
appearing in an expression that is subject to the array-to-pointer conversion (4.2) is converted to a pointer to an (n−1)
-dimensional array with rank j × ... × k
. If the *
operator, either explicitly or implicitly as a result of subscripting, is applied to this pointer, the result is the pointed-to (n − 1)
-dimensional array, which itself is immediately converted into a pointer.
您的選項是手動重新配置,以匹配表達式的類型的類型...
float (*temp)[1024] = a;
或使用多deminsional std::vector
或std::array
(C++ 11)...
std::array<std::array<int, 1024>, 1024> a;
auto temp = a;
由於這是C++的標籤,我建議你使用'std :: array,1024> a; auto&b = a;'假設你有一個C++ 11編譯器。 –
Borgleader