#include <iostream>
#include <vector>
usingnamespace std;
void generarMatriz(vector<vector<int> > &m){
cout << "Introduce los valores de la matriz ordenados por fila y columna: " << endl;
for (int i = 0; i < m.size(15); i++)//rows
for (int j = 0; j < m[0].size(10); j++){//columns
cout << "Introduce el valor de la fila " << i << " y columna " << j << " : ";
cin >> m[i][j];
}
}
void escribirMatriz(vector<vector<int> > &m){
for (int i = 0; i < m.size(15); i++){
for (int j = 0; j < m[0].size(10); j++)
cout << m[i][j] << "\t" ;
cout << endl;
}
cout << endl;
}
void transponer (vector<vector<int> > transponer(vector<vector<int> > &m)){
vector<vector<int> > nueva(m[0].size(10),vector<int>(m.size(15),0.0));
for ( int i = 0 ; i < m.size(10) ; i++ ){
for ( int j = 0 ; j < m[0].size(15) ; j++ )
nueva[j][i] = m[i][j];
m = nueva;
}
}
int main()
{
vector <vector<int> > m1(kMAXDIM,vector<int> (kMAXDIM)),
m2(kMAXDIM,vector<int> (kMAXDIM)),
result(kMAXDIM,vector<int> (kMAXDIM));
generarMatriz(m);
cout << "Matriz inicial: " << endl;
escribirMatriz(m);
transponer(m);
cout << "Matriz transpuesta " << endl;
escribirMatriz(m);
return 0;
}
Here are the erorrs:
|8|error: no matching function for call to 'std::vector<std::vector<int> >::size(int)'|
|9|error: no matching function for call to 'std::vector<int>::size(int)'|
|17|error: no matching function for call to 'std::vector<std::vector<int> >::size(int)'|
|18|error: no matching function for call to 'std::vector<int>::size(int)'|
|26|error: 'm' was not declared in this scope|
|42|error: 'kMAXDIM' was not declared in this scope|
|47|error: 'm' was not declared in this scope|
You already formed a matrix (vector of vectors) on line 42, 43, 44.
Your main function does not have a variable called m.
You have m1, m2, result defined.
The size() method of vector doesn't take any arguments, as Toaster already said.
(Requiring a size function to take in a size would defeat the purpose of a size function...)
Edit: You also don't have kMAXDIM defined.
if you want one dimension to be different than the other dimension, then you want something like: vector<int>(rows, vector<int>(columns))
consider making your vector<vector<thing>> a type masked name.
consider passing nueva into the function as a reference to save a copy. then just directly assign the result in the loop. The extra copy can be avoided entirely in a number of ways saving time.
you cannot do the initialize in the function parameter list. you have to do it before the function is called or inside the function.