method that returns an array of doubles
Feb 14, 2011 at 7:50pm UTC
I try creating a method that returns an array of doubles, but I get an error message when I try to compile
Gaus.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
class Gaus {
public :
Gaus ();
Gaus (double lam[], double sig[], double c, double varX, double varY, double varZ, double cenX[], double cenY[], double cenZ[], int varArraySize);
double eval ();
double [] getLambda ();
...
private :
double *lambda;
double *sigma;
double contourC;
double x;
...
};
error message
1>y:\windows\dunsonm\documents\visual studio 2008\projects\proj1assist\proj1assist\gaus.h(9) : error C3409: empty attribute block is not allowed
1>y:\windows\dunsonm\documents\visual studio 2008\projects\proj1assist\proj1assist\gaus.h(9) : error C2061: syntax error : identifier 'getLambda'
1>y:\windows\dunsonm\documents\visual studio 2008\projects\proj1assist\proj1assist\gaus.h(9) : error C2238: unexpected token(s) preceding ';'
1>y:\windows\dunsonm\documents\visual studio 2008\projects\proj1assist\proj1assist\gaus.h(10) : error C3409: empty attribute block is not allowed
1>y:\windows\dunsonm\documents\visual studio 2008\projects\proj1assist\proj1assist\gaus.h(10) : error C2061: syntax error : identifier 'getSigma'
What am I doing wrong?
Feb 14, 2011 at 8:03pm UTC
You can't return arrays like that ( line 9 ) you can only return them as pointers
Feb 14, 2011 at 8:04pm UTC
Thank you.
Feb 14, 2011 at 8:09pm UTC
double [] getLambda()
wont work. Write double * getLambda()
if you are going to return this ->lambda;
or std::vector< double > getLambda()
if you are going to generate a new array ( you could make it work with double *
then too but you may end up with a memory leak ).
Topic archived. No new replies allowed.