在C++中,你可以定義二維數組類型,如下所示(你需要現代的C++編譯器):
#include <array>
typedef std::array<std::array<Piece, 8>, 8> board_t;
如果你的編譯器不支持std::array
你可以用boost::array
代替:
#include <boost/array.hpp>
typedef boost::array<boost::array<Piece, 8>, 8> board_t;
現在你可以使用上面的類型。我可以看到你需要複製到該指針指向對象:
board_t* oldpointer = new board_t;
// do some with oldpointer
// now make a copy of the instance of the object oldpointer points to
// using copy-constructor
board_t* newpointer = new board_t(*oldpointer);
// now newpointer points to the newly created independent copy
// do more
// clean up
delete oldpointer;
// do more with newpointer
// clean up
delete newpointer;
解決方案是討論[這裏](http://stackoverflow.com/questions/4810664/how-do-i-use-arrays-in-c/4810676#4810676),看看「轉換」(約3頁面向下)。 – fredoverflow 2011-05-11 11:38:45