我知道有很多与此相关的问题,但它们的答案对我来说有点难以理解。对于几行不同的代码,我收到以下错误:
C:\Users\Jeff\AppData\Local\Temp\ccAixtmT.o:football.cpp:(.text+0x6f0): undefined
reference to `Player::set_values(int, std::string, float)'
从这些代码块:
class Player {
int playerNum;
string playerPos;
float playerRank;
public:
void set_values(int, string, float);
float get_rank(){ return playerRank; };
bool operator == (const Player &p1/*, const Player &p2*/) const
{
if(&p1.playerNum == &playerNum &&
&p1.playerPos == &playerPos &&
&p1.playerRank == &playerRank)
return true;
else
return false; };
};
这是引用子类的主要函数:
int main() {
ifstream infile;
infile.open ("input.txt", ifstream::in);
int numTeams;
string command;
while(!infile.fail() && !infile.eof()){
infile >> numTeams;
string name;
Player p;
int playNum;
string playPos;
float playRank;
Player all[11];
float ranks[11];
Team allTeams[numTeams];
for(int i=0; i<numTeams; i++){
infile >> name;
for(int j=0; j<11; j++){
infile >> playNum;
infile >> playPos;
infile >> playRank;
if(playPos == "QB")
p.set_values(playNum, playPos, (playRank*2.0));
else if(playPos == "RB")
p.set_values(playNum, playPos, (playRank*1.5));
else if(playPos == "WR")
p.set_values(playNum, playPos, (playRank/1.8));
else if(playPos == "TE")
p.set_values(playNum, playPos, (playRank*1.1));
else if(playPos == "GD")
p.set_values(playNum, playPos, (playRank/2.0));
else if(playPos == "TC")
p.set_values(playNum, playPos, (playRank/2.2));
else if(playPos == "CR")
p.set_values(playNum, playPos, (playRank/1.2));
all[j] = p;
allTeams[i].set_values(all, name);
}
}
infile >> command;
if (command == "play"){
int t1;
int t2;
infile >> t1;
infile >> t2;
play(allTeams[t1], allTeams[t2]);
}
else {
int t1;
int p1;
int t2;
int p2;
swap(allTeams[t1], allTeams[t1].get_player(p1), allTeams[t2], allTeams[t2].get_player(p2)); }
}
}