编译器告诉我我没有正确使用this指针

时间:2016-04-17 01:41:13

标签: c++ class pointers object this

这是错误的图片:

我创建了一个基本课程,可以保存运动队的信息。当我尝试使用this指针比较两个团队时,我收到一个错误。这是我的两个文件。希望这只是一个简单的错误。

Team.cpp

.retry()

Team.h

#include "Team.h"
#include <string>
#include <sstream>
using namespace std;

Team::Team()
{
  teamName = "The Strings";
  winNum = 0;
  lossNum = 0;
  numPlayers = 11;
  points = 0;
}

Team::Team(const char newName, int newPlayers)
{
  stringstream move;
  string strName;
  move << newName;
  move >> strName;
  teamName = strName;
  numPlayers = newPlayers;
}

void Team::display() // displays information about the team.
{
  cout << "Team name:" << teamName << endl;
  cout << "This team has " << numPlayers << " players" << endl;
  cout << "This team has " << winNum << " wins and " << lossNum << endl;
}
void Team::addWins() // increment the number of wins
{
  winNum = winNum + 1;
}
void Team::addLosses() // increment the number of losses.
{
  lossNum = lossNum + 1;
}

void Team::addPlayer(int nrPlayers)
{
  numPlayers = numPlayers + nrPlayers;
}

void Team::delPlayers(int nrPlayers)
{
  numPlayers = numPlayers - nrPlayers;
}

void Team::setTeam(char name[], int players, int wins, int losses)
{
  string strname(name);
  teamName = name;
  numPlayers = players;
  winNum = wins;
  lossNum = losses;
}

bool isBetter(const Team &other)
{
  if (this->points > other.points)
  {
    return true;
  }
  else
  {
    return false;
  }
}

int Team::getWins() // returns the number of wins for a team object
{
  return winNum;
}

int Team::getLosses() // returns the number of losses for a team object
{
  return lossNum;
}
int Team::getPoints() // returns the number of points a team has
{
  points = winNum - lossNum;
  return points;
}

0 个答案:

没有答案