Creating vector of objects

So I'm teaching myself c++ after having learned Java, and I'm making a basic rpg type game to do so. I'm having a hang up when trying to create a vector of Character objects that I have defined. This is the code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "Character.h"
#include <vector>
#ifndef _BATTLE_BASE_
#define _BATTLE_BASE_
class BattleBase{

private:
	vector<Character> * enemies;
	vector<Character> * chars;
public:

	bool attack(Character* at, Character* def);

};
#endif 


and this is the error

1
2
3
1>c:\users\jacob\documents\visual studio 2010\projects\balance\balance\battlebase.h(8): error C2143: syntax error : missing ';' before '<'
1>c:\users\jacob\documents\visual studio 2010\projects\balance\balance\battlebase.h(8): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\jacob\documents\visual studio 2010\projects\balance\balance\battlebase.h(8): error C2238: unexpected token(s) preceding ';'


I haven't even tried any implementation, as it does not seem to recognize the vector definition.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "Character.h"
#include <vector>
#ifndef _BATTLE_BASE_
#define _BATTLE_BASE_

using std::vector; // Do either this

class BattleBase{

private:
	std::vector<Character> * enemies; // Or this. Pick one.  Don't need both.
	std::vector<Character> * chars;
public:

	bool attack(Character* at, Character* def);

};
#endif 


This should help. Also, you're declaring a pointer to a vector, not a vector of pointers, if that was what you wanted to do.
Last edited on
Hm....
Last edited on
That worked, thanks, overlooked that vectors were part of the standard lib. And it is meant to be a pointer to a vector.
Topic archived. No new replies allowed.