Re: [Dev-C++] Need help translating from java to c++
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <qa...@ho...> - 2002-09-25 13:38:05
|
I found the way to create a multidimensional array with the size set at=
runtime.
The code is, in my case:
---
int row =3D atoi(argv[1]); // nbr of rows in the matrix
int col =3D atoi(argv[2]); // nbr of columns in the matrix
vector< vector <double> > v(row, vector<double>(col));
---
It now works fine to set the values with for instance
---
for(int i=3D0; i<row; i++)
for(int j=3D0; j<col; j++)
v[i][j] =3D (double) (i+j) / 3;
--
Now when this matrix is set I'd like to pass it on to a function:
---
void printMatrix(vector v){
for(int i=3D0; i<v.size(); i++){
for(int j=3D0; j<v[0].size(); j++)
cout << v[i][j] << " ";
cout << endl;
}
}
---
but the compiler complaints.
How shall I do to be able to pass it on to the function?
Regards
/J=F6rgen
*********** REPLY SEPARATOR ***********
On 2002-09-25 at 00:19 J=F6rgen wrote:
Hi list.
I'm quite new to c++ and i have written a program in java that I'd like (or=
rather need) to translate to c++, but I don't know how to solve this. How=
do I translate the following dummy java class to an equvalent c++ class?
public class Test{
double[][] input;
public Test(double[][] input){
this.input =3D input;
}
public double[][] getOutput(){
double[][] output =3D new double[input.length][input[0].length];
for(int i=3D0; i<output.length; i++)
for(int j=3D0; j<outout[0].length; j++)
output[i][j] =3D 2*input[i][j];
return output;
}
}
Thanks for your help
/J=F6rgen
|