cannot convert parameter 3 from 'double (*)[1]' to 'double *[]'

Hai.
I have 3 file; test.cpp file, makan.cpp file and header file.
The main function is in the test.cpp file where have a call function makan to compute the output from the calculation in function makan.
Unfortunately, when I compiled the code, it given an error --> cannot convert parameter 3 from 'double (*)[1]' to 'double *[]'.

Can I know how to handle this error?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
test.cpp file

#include "makan.h"

int main()
{
    //create input and output stream 
    ifstream inFile;
    ofstream result;

    double T;

    //result storage components
    double D1_rslt[ 1 ];
    double D2_rslt[ 1 ];
    double Ug_rslt[ 1 ];

    //Misc
    int i;
    int retval = 0;

    double D1;
    double D2;	
    double Ug;	
	
    double init_value[] = {0.000, 0.000};	

    double a[5];	//declaration of variable that hold the input data

    inFile.open("inputd.dat");	//open input file to access the input data

    //assigning the input data into an array form
    for(i = 0; i<5; i++)
    {
        inFile>>a[i];	//the input is hold in a[i]
    }
    inFile.close();

    result.open("result.dat");
    T = 0;
    i = 0;

    D1_rslt[ 0 ] = init_value[ 0 ];
    D2_rslt[ 0 ] = init_value[ 1 ];
    Ug_rslt[ 0 ] = Ug;

    for(i = 0; i < Step; i++)
    {
        D1 = D1_rslt[ 0 ];
        D2 = D2_rslt[ 0 ];
        Ug = Ug_rslt[ 0 ];

        makan(a,5,&Ug_rslt);

        if(!(i%100))
        {
            result<<fixed<<setprecision(5)<<T;
            result<<fixed<<setprecision(10)<<setw(10)<<Ug_rslt[ 0 ];		
            result<<endl;
        }
        T = T + Dt;
    }
    result.close();
}
]



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
makan.cpp file
//some part of the code

void makan(double a[], int length, double *Ug_rslt[])

	if(T >= time_b && T < (time_b + width))
	{
		d = a[0];		
	}
	else if(T >= time_L && T < (time_L + width))
	{
		d = a[1];
	}
	else if(T >= time_a && T < (time_a + width))
	{
		d = a[2];
	}
	else if(T >= time_d && T < (time_d + width))
	{
		d = a[3];
	}
	else if(T >= time_e && T < (time_e + width))
	{
		d = a[4];
	}
	else
	{
		d = No_more;
	}

	D = (d * 1000)/Mg;
	D1_rslt[ 0 ] = D1 + Dt * (Ag*D - D1/td);
	D2_rslt[ 0 ] = D2 + Dt * (D1_rslt[ 0 ]/td - D2/td);
	*Ug_rslt[ 0 ] = D2_rslt[ 0 ]/td;
}
Last edited on
cannot convert parameter 3 from 'double (*)[1]' to 'double *[]'

It would help, if you would also the line of code that the error refers to. (Compiler tells the line number in the message.)

So I guess: makan()

You have (essentially):
1
2
3
4
5
6
7
8
9
void foo( double * bar[] ) {
  *bar[0] = 3.14;
}

int main() {
  double gaz[ 1 ]; // why a one-element array?
  foo( &gaz ); // error
  return 0;
}

Why does the function take an array of pointers as argument?
Why not just the array, like this:
1
2
3
4
5
6
7
8
9
void foo( double * bar ) {
  bar[0] = 3.14;
}

int main() {
  double gaz[ 1 ];
  foo( gaz );
  return 0;
}


Or perhaps even:
1
2
3
4
5
6
7
8
9
void foo( double & bar ) {
  bar = 3.14;
}

int main() {
  double gaz;
  foo( gaz );
  return 0;
}

Thanks for the reply keskiverto. Yes. The error is on line 53 test.cpp.

I have made the correction as you suggested and pop up a debug error saying that the Ug is being used without initialized.

And when I initialized the Ug, it gives fatal error LNK1168
All LNK* are linker errors. The linker that you do use does have a manual that explains the error types.
See https://msdn.microsoft.com/en-us/library/hhbdtt6d.aspx
Topic archived. No new replies allowed.