i dont know how to use a vector and i tried but couldnt figure it out, i need to return an ARRAY of variables OR VECTOR of variables, which i dont know how to do, i believe arrays have to be the same type, but vector can be different (something like this...
return vector (string Type, int Attack, int Defense, int Health)
i'm trying to figure how to do something like this, because i have to do it in more than just this example (all i know is pair<?><?>,return make_pair which only returns 2 variables of any type)
static vector<int> default_vi //default vector of type int
void addvect(int n = 0, vector<int>& numbers = default_vi)
This way, you can put the vector in the calling function. Each time you call this function, it uses the address of the vector instead of making a new one. This way, you can keep adding values to 1 vector.
also, you can create a function that takes integer, and returns its corresponing 'type' as a string.
Also, if you want to return multiple types, you can just create a vector for each type and a function that takes each one as an argument and uses their addresses:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
static vector<int> default_vi
static vector<string> default_vs
void dosomthing(vector<string>& strings = default_vs, vector<int>& integers = default_vi)
if(strings.size() > 0)
//make sure there's somthing in strings before we do somthing to it... In this if we put our code for strings
if(integers.size() > 0)
//same process as with strings
//add to them, resize them, w.e.....
This is (in my opinion) the biggest difference between vectors and arrays: A lot less hassle. Arrays have to have every block of memory allocated before you can pass them from one function to another, whereas vectors can be simply passed. Optionally, you can take their address so that the function will directly modify that vector. This allows you to 'return' multiple values.
Why do you want to return a vector?
Each of those variables is already in your monster class, so simply allocate an instance of Monster and return it or even return Monster by value if you don't want to use new to allocate an instance. No need for a vector.
I gave you an example of this in your other thread.