Created
August 16, 2019 17:54
-
-
Save xxMrPHDxx/43291953c16d9f611e6883fd4f2e3206 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class Piece { | |
public: | |
int position; | |
Piece(){ position = -1; } | |
Piece(int position){ this->position = position; } | |
~Piece() { | |
cout << "Deleting piece!" << endl; | |
} | |
}; | |
class Tile { | |
public: | |
Piece* piece; | |
Tile(){ | |
piece = nullptr; | |
} | |
Tile(Tile& tile){ this->piece = tile.piece; } | |
Tile(Piece& pieceOnTile){ this->piece = &pieceOnTile; } | |
~Tile(){ | |
cout << "deleting piece pointer in Tile destructor!" << endl; | |
if(piece != nullptr) // This shouldn't be a problem right? | |
delete piece; | |
} | |
}; | |
int main(){ | |
Piece p1; | |
Piece p2(10); | |
Tile t1; | |
Tile t2(p2); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment