Is this a generic function of a function template?
1 2 3 4 5
|
template <typename T>
T lowerNumber(T x, T y) { // returns the lower number of x and y
return (x < y ? x : y);
}
|
How do you use STL vector class to declare a 7x24 matrix?
1 2 3
|
const int N_DAYS = 7;
const int N_HOURS = 24;
int schedule[N_DAYS][N_HOURS];
|
Is this it:
vector< vector<int> >schedule(N_DAYS, vector<int>(N_HOURS));
?
Last edited on
> Is this a generic function of or a function template?
It is both. C++ uses templates to support generic programming.
> Is this it: vector< vector<int> >schedule(N_DAYS, vector<int>(N_HOURS));
?
Yes.
Since the sizes are constants, std::array<> is another option.
std::array< std::array<int,N_HOURS>, N_DAYS > schedule {};