C++ 内存错误c++;私有整数

C++ 内存错误c++;私有整数,c++,class,memory,C++,Class,Memory,我正在做一个项目,我必须使用一个名为numberOfMatches的私有int。 这是Player.h中Player类中的代码: 当我试图设置numberOfMatches上的数字时,其值不会改变 int amount = 10; Player* team = new Player(amount); for (int x = 0; x < 10; x++) { int matches = x; team[x].setnumberOfMatches(matches); }

我正在做一个项目,我必须使用一个名为
numberOfMatches
的私有int。 这是Player.h中Player类中的代码:

当我试图设置
numberOfMatches
上的数字时,其值不会改变

int amount = 10;
Player* team = new Player(amount);
for (int x = 0; x < 10; x++)
{
    int matches = x;
    team[x].setnumberOfMatches(matches);
}
使用
团队[0].set()时并非如此

有人知道什么地方可能出错吗?

这段代码

Player* team = new Player(amount);
分配一个玩家对象

此代码访问从未分配的播放器对象(当x大于零时):

for(int x=0;x<10;x++)
{
int=x;
团队[x]。setnumberOfMatches(比赛);
}

为什么要使用指针和
新玩家
?在原始代码中,在执行Player*team=new Player[amount]时还有很多其他的事情。它最初是从文本文件中读取字符串,将其转换为int,然后给我们amount*teamnew Player(amount)不分配amount Player。不过,这不是问题所在。球队没有什么问题。我试过了,它确实管用。问题在于匹配的数量
"<Unable to read memory>" on numberOfMatches. 
Player* team = new Player(amount);
for (int x = 0; x < 10; x++)
{
 int matches = x;
 team[x].setnumberOfMatches(matches);
}