0
如何使用指向該數組的指針訪問二維數組的元素?如何正確訪問指向2維數組的指針的元素?
std::recursive_mutex *(*A)[2];
std::recursive_mutex *B[2];
B[0] = new std::recursive_mutex[some_size];
B[1] = new std::recursive_mutex[some_size];
A = &B;
//accessing
//A[0][0]
//A[1]
//A[1][0]
//will not work (since the pointers do not point to the same locations as
//B[0][0]
//B[1]
//B[1][0]
獎金的問題:是否有初始化一個更好的方法嗎? (不使用的std ::向量)
你試過用''(* A)[0] [0]'來訪問A嗎? – Amadeus
是的。類型不匹配。 – mort
這不是一個二維數組,而是一個指向兩個指針數組的指針。一個比你的獎金問題更好的問題是爲什麼你需要初始化這種類型的對象?也許有更好的方法 –