拿這個程序爲例:如何刪除我創建的這個對象?
class Piece
{
public:
Piece(bool color);
protected:
bool color;
};
Piece::Piece(bool color)
{
this->color = color;
}
//-----------------------------
class King : public Piece
{
public:
King(bool color);
};
King::King(bool color) : Piece(color)
{
// empty
}
//-----------------------------
class Tile
{
public:
// constructors/destructors
Tile(Piece * ppiece, int rrow, int ccol);
~Tile();
private:
Piece * piece;
int row, col;
};
Tile::Tile(Piece * ppiece, int rrow, int ccol)
{
this->ppiece = piece;
this->row = rrow;
this->col = ccol;
}
//---------------------------
int main()
{
Tile * tile = new Tile(new King(0), 1, 1);
}
在功能main()
我宣佈一個新的King
,並把它傳遞給Tile
構造。如何刪除我創建的King
對象?
http://msdn.microsoft.com/en-us/library/h6227113.aspx – noMAD 2012-03-11 06:06:41