Okay let's back up a bit and look over a similar but simpler function:
1 2 3 4 5 6 7 8 9 10
|
int func( double param )
{
//...
}
int main()
{
int x = func(10.5);
int y = func(11.6);
}
| |
In this example, 'func' takes a double as a parameter and returns an int. Hopefully that shows the syntax a bit more clearly:
|
return_type function_name( parameter_type parameter_name )
| |
When we call the function, we have to give it a double to fill in that parameter, hence why there's a floating point value when we call it:
1 2
|
int x = func(10.5); // <- the 10.5 here is our 'double' parameter
// whatever 'func' returns gets assigned to 'x'
| |
So now that that's [hopefully] understood... let's go back and look at vector:
1 2 3
|
vector<int> grades;
//...
grades.push_back(84);
| |
A vector is basically just a resizable array... but a resizable array of
whats? The type in the <angle brackets> indicates what we have a vector
of. So here...
vector<int>
indicates we have a vector of ints.
We could have a vector<double>... or a vector<string>... or a vector<any_other_type_imaginable>. All of those vectors would be considered different types. A vector<int> is a different type from vector<double> just as 'int' is a different type from 'double'.
So
vector<int>
is the type. So this function:
int sumVector (vector<int> vect)
Is the same as this function:
int func( double param )
The only difference is that instead of passing a double as a parameter, we're passing a vector of ints.