invalid types ‘int[int]’ for array subscript

I'm trying to make a simple console RPG game

This is .h file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
  #include<iostream>
#include<cstdlib>
#include<ctime>
#include<string>
using namespace std;
#ifndef GAME_H_
#define GAME_H_

class game
{
public :
	game();
	string start();
	int hero(string name,string weapon,int ap,int dp,int hp,int l);
	void enemy(string name,string weapon,int ap,int dp,int hp,int l);
	int lvl (int score);
private:
	string name;
	string weapon[10];
	string pweapon;
	string eweapon;
	int score;
	int ap[8]={10,14,18,20,24,26,27,29};
	int *pap;
	int *eap;
	int dp[10];
	int *pdp;
	int *edp;
	int hp[10];
	int *php;
	int *ehp;
	int l;
};



#endif /* GAME_H_ */ 


I got the Error in "ap" array invalid types ‘int[int]’ for array subscript
I'm using Eclipse mars on linux



And this .cpp file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include"game.h"
game::game()
{
	 score=0;
	 *pap=0;
	 *eap=0;
	 *pdp=0;
	 *edp=0;
	 *php=0;
	 *ehp=0;
	 l=0;
}
string game::start()
{
	cout<<"please enter your name: ";
	getline(cin,name);
	return name;
}
int game::hero(string name,string weapon,int ap,int dp,int hp,int l)
{
	switch (l)
	{
	case 1:
		pweapon=weapon[0];
		pap=ap[0];
		pdp=dp[0];
		php=hp[0];
		break;
	}
}

1
2
3
4
5
6
7
8
9
10
11
12
int game::hero(string name,string weapon,int ap /*ap is just one number*/,int dp,int hp,int l)
{
	switch (l)
	{
	case 1:
		pweapon=weapon[0];
		pap=ap[0]; //not an array
		pdp=dp[0];
		php=hp[0];
		break;
	}
}
Thx it's solved
But I want to know your opinion about the code
I don't have exprience with games and just I learned c++ self study and try to make a game
.h file
Lines 1-3: I don't see any use of iostream, ctime, or cstdlib in your header. No need to include these headers here.
Line 5: Never put using namespace std in a header file.
Lines 6-7: These should be the first two lines of the header.

.cpp file
Lines 5-10: These are all uninitialized pointers. You're storing zeroes into random memory.

Topic archived. No new replies allowed.