by using two functions. First function has 1 matrix and the second function 2 matrices. |
That makes little sense. Homework that forces "unnatural" solutions ...
Never mind, you do show
1 2 3 4 5 6
|
T foo()
{
U bar;
// code
return bar;
}
|
where
T = int
and
U = std::vector<int>
.
If you have written such code and attempted to compile, the compiler should say that it does not know how to convert
std::vector<int>
into single
int
.
That is not even necessary. std::vectors are objects that have
copy constructor and
copy assignment operators; they can be copied, as in return value of a function.
http://www.cplusplus.com/reference/vector/vector/operator=/
http://www.cplusplus.com/reference/vector/vector/vector/
In other words, this is legal:
1 2 3 4 5 6 7 8 9 10
|
std::vector<int> foo()
{
std::vector<int> bar;
// code
return bar;
}
int main() {
std::vector<int> m0 = foo();
}
|
std::vector is essentially a 1D array. One can use index math to treat it as a 2D array.
Alternatively, one can create a vector that stores vectors, e.g.
std::vector<std::vector<int>>
.
The assignment in general ... if not arbirarily restricted ... I would write:
* a function that returns "matrix" of some sort, filled with numbers
* a function that computes the sum of such matrix
* a function that prints a matrix
The first function is called three times to create three matrices.
The second function is called three times to get three sums.
The last function is used to print the matrix that corresponds to the largest sum.