来自C++新手的另一个问题.
我收到编译器错误"不匹配'运算符=='"以获取以下代码块
void swap(Team t1, Player p1, Team t2, Player p2){
Player new_t1[11];
Player new_t2[11];
for(int i=0; i<11; i++){
new_t1[i] = t1.get_player(i);
new_t2[i] = t2.get_player(i);
if(new_t1[i] == p1){
new_t1[i] = p2;
}
if(new_t2[i] == p2){
new_t2[i] = p1;
}
}
cout << "Players swapped.";
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我是C++的新手,我正在尝试编写一个模拟足球比赛的程序.我收到一个编译器错误,指出函数get_rank,get_player和get_name未在此范围内声明.任何帮助是极大的赞赏!
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class Player {
int playerNum;
string playerPos;
float playerRank;
public:
void set_values(int, string, float);
float get_rank(){ return playerRank; };
};
class Team {
Player team[];
string teamName;
public:
void set_values(Player[],string);
Player get_player(int a) { return team[a]; };
string get_name() { return teamName; };
};
void play(Team t1, Team t2){
float t1rank = 0.0;
float t2rank = 0.0;
for(int i=0; i<11; i++){
t1rank += get_rank(get_player(t1, i));
}
for(int j=0; j<11; j++){ …Run Code Online (Sandbox Code Playgroud)