在 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;