Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. Generalla krav
  2. *Konstruktor och destruktor finns i alla klasser: Ej korrekt, yatzee konstruktorn ger fel värde till nrOfplayer, leder till crash
  3. *Tilldelningsoperator och kopieringskonstruktor finns i relevanta klasser: Ej korrekt, tilldeningsoperator saknas
  4.  
  5. Yatzee
  6. Funktionen addPlayer: Ej korrekt, dessutom tas objektet bort direkt efter det lags till
  7. ???vill jag ha en konstruktor för varje situation???
  8. Yatzee::Yatzee(string name)
  9. {
  10. this->name = name;
  11. this->nrOfPlayers = 0;
  12. this->turn = 0;
  13. //this->players = new string[this->capacity];
  14. this->capacity = 10;
  15. this->protocols = new Protocol*[this->capacity];
  16. }
  17.  
  18. Yatzee::Yatzee(int nrOfPlayers)
  19. {
  20. this->name = "?";
  21. this->nrOfPlayers = nrOfPlayers;
  22. this->turn = 0;
  23. //this->players = new string[this->capacity];
  24. this->capacity = 10;
  25. this->protocols = new Protocol*[this->capacity];
  26. }
  27.  
  28. Yatzee::Yatzee(string name, int nrOfPlayers)
  29. {
  30. this->name = name;
  31. this->nrOfPlayers = nrOfPlayers;
  32. this->turn = 0;
  33. //this->players = new string[this->capacity];
  34. this->capacity = 10;
  35. this->protocols = new Protocol*[this->capacity];
  36. }
  37.  
  38. Yatzee::Yatzee(const Yatzee &other)
  39. {
  40. this->capacity = other.capacity;
  41. this->nrOfPlayers = other.nrOfPlayers;
  42. this->turn = other.turn;
  43. this->capacity = other.capacity;
  44.  
  45. this->protocols = new Protocol*[this->capacity];
  46.  
  47. for (int i = 0; i < this->capacity; i++)
  48. {
  49. this->protocols[i] = new Protocol(*other.protocols[i]);
  50. }
  51. }
  52.  
  53. Yatzee::Yatzee()
  54. {
  55. this->name = "Yatzee";
  56. this->nrOfPlayers = 0;
  57. this->turn = 0;
  58. //this->players = new string[this->capacity];
  59. this->capacity = 10;
  60. this->protocols = new Protocol*[this->capacity];
  61. }
  62.  
  63. ???Vad gör jag fel??? och varför tas den nya spelaren bort direkt???
  64. void Yatzee::addPlayer(string name)
  65. {
  66. Protocol * toAdd = new Protocol(name);
  67.  
  68. this->protocols[this->nrOfPlayers] = toAdd;
  69. //this->players[this->nrOfPlayers] = name;
  70. this->nrOfPlayers++;
  71. delete toAdd;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement