Weird error with vector

Hi I am trying to print out information from the vector called choosepoke but some weird error comes up whenever I try to compile it. It says:

1>c:\users\ashran\documents\visual studio 2012\projects\project16\project16\pokemon.h(29): error C2065: 'Pokemon' : undeclared identifier
1>c:\users\ashran\documents\visual studio 2012\projects\project16\project16\pokemon.h(29): error C2923: 'std::vector' : 'Pokemon' is not a valid template type argument for parameter '_Ty'
1>c:\users\ashran\documents\visual studio 2012\projects\project16\project16\pokemon.cpp(248): warning C4018: '<' : signed/unsigned mismatch
1> Source.cpp
1>c:\users\ashran\documents\visual studio 2012\projects\project16\project16\pokemon.h(29): error C2065: 'Pokemon' : undeclared identifier
1>c:\users\ashran\documents\visual studio 2012\projects\project16\project16\pokemon.h(29): error C2923: 'std::vector' : 'Pokemon' is not a valid template type argument for parameter '_Ty'
1>c:\users\ashran\documents\visual studio 2012\projects\project16\project16\source.cpp(27): error C2664: 'printpokelist' : cannot convert parameter 1 from 'std::vector<_Ty>' to 'std::vector<_Ty> &'
1> with
1> [
1> _Ty=Pokemon
1> ]
1> and
1> [
1> _Ty=int
1> ]

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
38
39
40
41
  //************************Pokemon Objects**************************************************
	Pokemon Bulbasaur(1,"Bulbasaur", "Tackle", "Growl", "Sand Attack", "Absorb", 200);
	Pokemon	Ivysaur(2, "Ivysaur", "Razor Leaf", "Sunny Day", "Solarbeam", "Body Slam", 150);
	Pokemon Venasaur(3, "Venasaur", "Solarbeam", "Frenzy Plant", "Skull Bash", "Giga Drain", 300);

//************************Adding Pokemon into Vector***************************************
	vector <Pokemon> choosepoke; 
	choosepoke.push_back(Bulbasaur);
	choosepoke.push_back(Ivysaur);
	choosepoke.push_back(Venasaur);

//***********************List of Pokemon to Choose*****************************************
	printpokelist(choosepoke);

//*********printpokelist Function Implementation*********
void printpokelist(vector <Pokemon> & choosepokemon)
{
	
	string list = "List of Pokemon"; 
	cout << list << endl;
	
	for(int i = 0; i < list.size(); i++)
	{
		cout << '-'; 
	}
	cout << endl << endl;
	
	cout << "Dex #";
	cout.width(30);
	cout << "Pokemon's Name" << endl << endl;
	
	int size = choosepokemon.size();

	for(int i = 0; i < size; i++)
	{
		cout << choosepokemon[i].getdexnumber();
		cout.width(30);
		cout << choosepokemon[i].getname() << endl;
	}
}
Last edited on
It appears that your 'pokemon.h' file doesn't know what Pokemon is - have you tried to use it before declaring it? Also, is this the whole header file you have given us? Or is it part of the source file? It would also help if you gave us hints as to the line numbers so that they match up with the error messages received.
This is my whole header 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef POKEMON_H
#define POKEMON_H

#include <string>
#include <iostream>
#include <vector>
#include <iomanip>

using namespace std;

const int MAX = 10;

//Effect: Prints out the whole map.
void printmap(const int map[][MAX]);

//Effect: Prints out the command moves. 
void printmoves();

//Effect: Finds the row location of the player or "1".
int findrowlocation(const int map[][MAX]);

//Effect: Find the column location of the player or "1".
int findcollocation(const int map[][MAX]);

//Effect: Make the move on moving around the map. 
void makeamove(int map[][MAX], bool &didamove);

//Effect: Print list of pokemon to choose from.
void printpokelist(vector<Pokemon>&choosepokemon);


class Pokemon 
{
public: 
	//constructors
	Pokemon();
	Pokemon(int number, string name, string move1, string move2, string move3, string move4, int hp);
	//getters
	int getdexnumber() const;
	string getname() const;
	string getmove1() const;
	string getmove2() const;
	string getmove3() const; 
	string getmove4() const;
	int gethp() const;
	//setters
	void setdexnumber(int dexnum);
	void setname(string n);
	void setmoveset(string move[4]);
	void sethp(int hitpoint);
	//function
	void damagecalculation(string move, int &hp);
	void pokemonappear();

	

private:
	//data members
	int dexnumber;
	string name; 
	string moveset[4];
	int hp; 
};

class Moves 
{
public:
	//constructors
	Moves();
	Moves(int dmg, int PP, int damageboost);
	//getters
	int getdamage() const;
	int getpp() const;
	int getboost() const;
	//setters
	int setdamage(int damage);
	int setpp(int pp);
	int setboost(int boost);
private:
	int damage;
	int pp;
	int boost;
};






#endif
Yes, you should move line 29 to after the definition of the Pokemon class. In this case, a forward declaration isn't sufficient, either - it must be able to expand the size of the object, etc.

EDIT:
Also, as a general rule, try to avoid using namespace std; in headers, and only include the files that you are actually using in that header. Why do you need iostream and iomanip?
Last edited on
This is my source 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <string>
#include <iomanip>
#include <time.h>
#include <vector>
#include "pokemon.h"


using namespace std;


int main()
{
	system("title Pokemon Map");
//************************Pokemon Objects**************************************************
	Pokemon Bulbasaur(1,"Bulbasaur", "Tackle", "Growl", "Sand Attack", "Absorb", 200);
	Pokemon	Ivysaur(2, "Ivysaur", "Razor Leaf", "Sunny Day", "Solarbeam", "Body Slam", 150);
	Pokemon Venasaur(3, "Venasaur", "Solarbeam", "Frenzy Plant", "Skull Bash", "Giga Drain", 300);

//************************Adding Pokemon into Vector***************************************
	vector <Pokemon> choosepoke; 
	choosepoke.push_back(Bulbasaur);
	choosepoke.push_back(Ivysaur);
	choosepoke.push_back(Venasaur);

//***********************List of Pokemon to Choose*****************************************
	printpokelist(choosepoke);
	
	
//************Map Movement*********************
	//bool didamove = true;
	//int map[MAX][MAX] = {{0}};
	//map[0][0] = 1;//starting point is in (0,0)
	//printmap(map);
	//while(true)
	//{
	//	makeamove(map,didamove);
	//	if(didamove)
	//	{
	//	
	//}
//*********************************************

	
	
	

	

	
	




	return 0;
}





Topic archived. No new replies allowed.