Wandbox
SettingsLog
SettingsLog
Language
GitHubLogin
Ran/Viewed Log

Viewed less than a minute ago

QYjxknSzo77JYHAv

C++ gcc 12.1.0

Created at 1 minute ago

Created by anonymous

Author

anonymous

1 minute ago

Language

C++

Compiler

gcc 12.1.0

Options
Warnings
Don't Use Boost
C++11
no pedantic
セオライド・テクノロジー㈱株式会社フィックスターズ

Author

anonymous

1 minute ago

›
⌄
⌄
⌄
⌄
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <cstring>

class Player {
private:
char* name;
int elo;
int score;

public:
Player(const char* const name, const int elo);
~Player();

// The accessor, mutator and print functions are given
int getELO() const { return elo; }
int getScore() const { return score; }

void addScore(const int points) { score += points; }

void print() const {
std::cout << name << " (" << elo << ")";
}
};

Player::Player(const char* const name, const int elo) {
this->name = strdup(name);
this->elo = elo;
this->score = 0;
}

class PlayerList {
private:
int numPlayers;
Player** players;

public:
PlayerList();
PlayerList(const PlayerList& list);
~PlayerList();

// The following accessor functions are given
int getNumPlayers() const { return numPlayers; }
Player* getPlayer(const int index) const { return players[index]; }

void addPlayer(Player* const player);
void sort();
PlayerList* splice(const int startIndex, const int endIndex) const;
};

PlayerList::PlayerList(){
numPlayers = 1;
players = new Player*[1];
players[0] = new Player("a", 0);
}
PlayerList::PlayerList(const PlayerList& list){ std::cout << "don't use me!" << std::endl; }
PlayerList::~PlayerList(){}

int main(void) {
int some_integer_not_important_to_question = 1;
PlayerList* Groups = new PlayerList [some_integer_not_important_to_question];

Groups[0].getPlayer(Groups[0].getNumPlayers() - 1)->print(); //This works
Groups[0].getPlayer(Groups[0].getNumPlayers() - 1)->addScore(2); //This doesn't work

return 0;
}

$ g++ prog.cc -Wall -Wextra -std=c++11
prog.cc: In copy constructor 'PlayerList::PlayerList(const PlayerList&)':
prog.cc:55:42: warning: unused parameter 'list' [-Wunused-parameter]
   55 | PlayerList::PlayerList(const PlayerList& list){ std::cout << "don't use me!" << std::endl; }
      |                        ~~~~~~~~~~~~~~~~~~^~~~
a (0)
Exit Code:
0
セオライド・テクノロジー㈱株式会社フィックスターズ