Vector of Objects

Is it possible with Visual c++ to have an instance variable of an object to be a vector of an object?
1
2
3
4
5
6
7
8
9
ref class statList
{
public:
	vector<int> test;

	statList(void);
	int getSize();
	void add(pokeStats^ element);
};


I have the vector<int> test; commented out.

Alright, this is the code I'm using and the where the problem is. I have the pokeStats.h included and its an object I've made.

1
2
3
4
5
6
7

std::vector<pokeStats^> list;
void statList::add(pokeStats^ element)
{
	
	list.push_back(element);
}


I fail to see why there is an compiling error. Here is the error:
1>c:\users\justin\documents\visual studio 2008\projects\ev counter\ev counter\statList.h(8) : error C2143: syntax error : missing ';' before '<'
1>c:\users\justin\documents\visual studio 2008\projects\ev counter\ev counter\statList.h(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\justin\documents\visual studio 2008\projects\ev counter\ev counter\statList.h(8) : error C2238: unexpected token(s) preceding ';'
Last edited on
Erm, you are mixing CLI/C++ and C++...either use one or the other.

In C++, the get a pointer you use * like this: std::vector<int*>
In CLI/C++, you use ^ to get a "pointer" (it's more of a handle)
I've tried using the asterisk (*) verses the caret (^) and it gives me new errors.

error C3699: '*' : cannot use this indirection on type 'pokeStats'
1> compiler replacing '*' with '^' to continue parsing


So I changed them all to carets (^)
Last edited on
the carrot (^)


It's spelled "caret"

carrots are vegetables.
Oh I see. You are using CLI/C++, so you cannot use std::vector, etc. Instead, you would have use System::array or whatever the equivalent types are.
Topic archived. No new replies allowed.