请求数组成员时收到错误 [英] Receiving an error when requesting members for an array
问题描述
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int winnings[4] = {0,0,0,0};
int* p_winnings = winnings;
void CalculateGame(int* p_games);
int main()
{
int games[6] = {12,13,14,23,24,34};
int* p_games = games;
int favorite_team,games_played,team1,team2,score1,score2,i;
ifstream data("DATA11.txt");
data >> favorite_team >> games_played;
vector<int> standings(4);
for (i = 0;i < 4; i++)
standings[i] = 0;
for (i = 0;i < games_played;i++)
{
data >> team1 >> team2 >> score1 >> score2;
if (score1 > score2)
standings[team1 - 1] += 3;
if (score1 == score2)
standings[team1-1]++,standings[team2-1]++;
if (score1 < score2)
standings[team2-1] += 3;
for (i = 0; i < games.size();i++)
{
int temp1,temp2,temp;
temp = games[i];
temp2 = temp % 10;
temp /= 10;
if (temp2 == team2 && temp == team1)
games.erase(i);
}
}
}
为什么当我请求的成员(如.size()或.erase())的阵列比赛我得到一个错误说为成员的请求的 _ 的_游戏是的非类类型为int [6]
Why when i request for a member(like .size() or .erase() ) of the array games i get an error saying "request for member __ in games which is of a non-class type int [6]"
推荐答案
普通的老C数组没有成员。所以它没有尺寸
或删除
。如果你的没有的希望它有成员虽然C ++ 11提供了一个名为的std ::阵列&LT类; T,N&GT;
可以是通过简单地做在你的情况下使用的std ::阵列&LT; INT,6'游戏= {...}
。但是请注意,的std ::阵列
不具有删除
成员函数,但它有一个尺寸
成员函数。
Plain old C arrays don't have members. So it has no size
or erase
. If you did want it to have members though, C++11 offers a class called std::array<T,N>
which can be used in your case by simply doing std::array<int, 6> games = { ... }
. Note however that std::array
does not have an erase
member function, but it has a size
member function.
这篇关于请求数组成员时收到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!