Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Generalla krav
- *Konstruktor och destruktor finns i alla klasser: Ej korrekt, yatzee konstruktorn ger fel värde till nrOfplayer, leder till crash
- *Tilldelningsoperator och kopieringskonstruktor finns i relevanta klasser: Ej korrekt, tilldeningsoperator saknas
- Yatzee
- Funktionen addPlayer: Ej korrekt, dessutom tas objektet bort direkt efter det lags till
- ???vill jag ha en konstruktor för varje situation???
- Yatzee::Yatzee(string name)
- {
- this->name = name;
- this->nrOfPlayers = 0;
- this->turn = 0;
- //this->players = new string[this->capacity];
- this->capacity = 10;
- this->protocols = new Protocol*[this->capacity];
- }
- Yatzee::Yatzee(int nrOfPlayers)
- {
- this->name = "?";
- this->nrOfPlayers = nrOfPlayers;
- this->turn = 0;
- //this->players = new string[this->capacity];
- this->capacity = 10;
- this->protocols = new Protocol*[this->capacity];
- }
- Yatzee::Yatzee(string name, int nrOfPlayers)
- {
- this->name = name;
- this->nrOfPlayers = nrOfPlayers;
- this->turn = 0;
- //this->players = new string[this->capacity];
- this->capacity = 10;
- this->protocols = new Protocol*[this->capacity];
- }
- Yatzee::Yatzee(const Yatzee &other)
- {
- this->capacity = other.capacity;
- this->nrOfPlayers = other.nrOfPlayers;
- this->turn = other.turn;
- this->capacity = other.capacity;
- this->protocols = new Protocol*[this->capacity];
- for (int i = 0; i < this->capacity; i++)
- {
- this->protocols[i] = new Protocol(*other.protocols[i]);
- }
- }
- Yatzee::Yatzee()
- {
- this->name = "Yatzee";
- this->nrOfPlayers = 0;
- this->turn = 0;
- //this->players = new string[this->capacity];
- this->capacity = 10;
- this->protocols = new Protocol*[this->capacity];
- }
- ???Vad gör jag fel??? och varför tas den nya spelaren bort direkt???
- void Yatzee::addPlayer(string name)
- {
- Protocol * toAdd = new Protocol(name);
- this->protocols[this->nrOfPlayers] = toAdd;
- //this->players[this->nrOfPlayers] = name;
- this->nrOfPlayers++;
- delete toAdd;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement