MrStill

October 8th, 2009, 05:07 PM

Hi,

I am an intermediate Java programmer and I am trying to learn C++ so that I can be more versatile. I am working on a function definition which returns a vector of vectors. My code looks like this:

vector< vector<double> > NumericalAnalysis::extrapolate(double h, double x, double tolerance){

vector< vector<double> > output(1, vector<double>(1));

output[0][0] = derivative(x, h);

int row = 1;

do{

output.push_back(vector<double>(row + 1));

output[row][0] = derivative(x, h / (row + 1));

for(int column = 1; column <= row; column++){

output[row][column] = 1 / (pow(4, column - 1) - 1);

output[row][column] *= (output[row][column - 1] - output[row - 1][column - 1]);

output[row][column] += output[row][column - 1];

}

row++;

}while(fabs(output[row][row] - output[row - 1][row - 1]) > tolerance );

return output;

}

And my function header in the .h file looks like this:

vector< vector<double> > extrapolate(double,double, double);

G++ dose not like my function header:

NumericalAnalysis.h:9: error: ISO C++ forbids declaration of ‘vector’ with no type

NumericalAnalysis.h:9: error: expected ‘;’ before ‘<’ token

If anyone has any ideas on what I am doing wrong, they would be much appreciated. And though I am a Java programmer, I do understand pointers.

Thanks

I am an intermediate Java programmer and I am trying to learn C++ so that I can be more versatile. I am working on a function definition which returns a vector of vectors. My code looks like this:

vector< vector<double> > NumericalAnalysis::extrapolate(double h, double x, double tolerance){

vector< vector<double> > output(1, vector<double>(1));

output[0][0] = derivative(x, h);

int row = 1;

do{

output.push_back(vector<double>(row + 1));

output[row][0] = derivative(x, h / (row + 1));

for(int column = 1; column <= row; column++){

output[row][column] = 1 / (pow(4, column - 1) - 1);

output[row][column] *= (output[row][column - 1] - output[row - 1][column - 1]);

output[row][column] += output[row][column - 1];

}

row++;

}while(fabs(output[row][row] - output[row - 1][row - 1]) > tolerance );

return output;

}

And my function header in the .h file looks like this:

vector< vector<double> > extrapolate(double,double, double);

G++ dose not like my function header:

NumericalAnalysis.h:9: error: ISO C++ forbids declaration of ‘vector’ with no type

NumericalAnalysis.h:9: error: expected ‘;’ before ‘<’ token

If anyone has any ideas on what I am doing wrong, they would be much appreciated. And though I am a Java programmer, I do understand pointers.

Thanks