# function prototype

• 04-15-2007
shuo
function prototype
Hi

The following function declaration doesn't work. It takes object flowfield and returns object matrix_square.

Code:

``` matrix_square eigenvalue(flow_field, flow_field); matrix_square eigenvalue_plus(flow_field &ob, flow_field &ob1) {   int i;   matrix_square temp;     for (i = 0; i < Grids; i++)       temp.ptr[i] = ob.ptr[i];                                                        //Element 11     for (i = 4*Grids; i < 5*Grids; i++)       temp.ptr[i] = ob.ptr[i - 4*Grids] + ob1.ptr[i - 4*Grids];                //Element 22     for (i = 8*Grids; i < 9*Grids; i++)       temp.ptr[i] = 0;                                                                //Element 33 return temp; }```
• 04-15-2007
Dave_Sinkula
It's usually easiest to copy and paste in order to avoid issues like this.
Code:

`matrix_square eigenvalue(flow_field &, flow_field &);`
?

Leaving the parameter name in there costs you nothing.
• 04-16-2007
shuo
I get the following error when I declare:

Code:

```matrix_square eigenvalue(flow_field &, flow_field &); matrix_square eigenvalue(flow_field &ob, flow_field &ob1) {   int i;   matrix_square temp;     for (i = 0; i < Grids; i++)       temp.ptr[i] = ob.ptr[i];                                                        //Element 11     for (i = 4*Grids; i < 5*Grids; i++)       temp.ptr[i] = ob.ptr[i - 4*Grids] + ob1.ptr[i - 4*Grids];                //Element 22     for (i = 8*Grids; i < 9*Grids; i++)       temp.ptr[i] = ob.ptr[i - 8*Grids] - ob1.ptr[i - 8*Grids];                //Element 33 return temp; }```
matrix_functions.C:110: error: ‘matrix_square’ does not name a type
• 04-16-2007
shuo
Note the declaration is from a header file while the code itself is stored in a .C file
• 04-16-2007
nvoigt
Make sure that matrix_square is declared before your function prototype, usually by including it's headerfile.
• 04-17-2007
shuo
When I compile I type:

g++ -o supersonic_ob supersonic_ob.C matrix_functions.C -lm

supersonic_ob.C

Code:

``` //Declare header files #include "matrix_square.H"  //Class definition #include "matrix_functions.H"  //Function prototype int main(){ flow_field ob, ob1; matrix_square b; b = eigenvalue_minus(ob, ob1); }```
matrix_function.C

Code:

``` matrix_square eigenvalue_minus(flow_field &ob, flow_field &ob1) {   int i;   matrix_square temp;     for (i = 0; i < Grids; i++)       temp.ptr[i] = 0;                                                                //Element 11     for (i = 4*Grids; i < 5*Grids; i++)       temp.ptr[i] = 0;                                                                //Element 22     for (i = 8*Grids; i < 9*Grids; i++)       temp.ptr[i] = ob.ptr[i - 8*Grids] - ob1.ptr[i - 8*Grids];                //Element 33 return temp; }```
matrix_function.H
Code:

`matrix_square eigenvalue_minus(flow_field &, flow_field &);`
Hope I am clear enough.
• 04-17-2007
Dave_Sinkula
All headers that are part of the translation unit are relevant and should be posted for any real analysis: can you also post "matrix_square.H"?
• 04-18-2007
shuo
Here's matrix_square.H

Code:

```class matrix_square { public:   int i;   double *ptr;   matrix_square(){     ptr = new double[square_points];     assert( ptr!= 0);  for(i = 0; i < square_points; i++)         ptr[i] = 0;} //copy constructor matrix_square(const matrix_square &a){   int i;   ptr = new double[square_points];   for(i = 0; i < square_points; i++)     ptr[i] = a.ptr[i]; }   ~matrix_square(){     delete [] ptr; } };```
• 04-19-2007
Daved
Does matrix_function.C #include "matrix_square.H"? It should, because it uses a matrix_square. (It should also #include "matrix_functions.H".)

Each .C file should #include any .h files that contain declarations it needs.
• 04-19-2007
shuo
Thanks you guys, got it working.