error: incompatible types in assignment

**Edit I have now changed the way i am approaching this problem see second post

I am gett this error "vbays.cpp:74: error: incompatible types in assignment of ‘double’ to ‘double [1]’ " but I thought i was sending in my functions in the proper way that you guys showed me but i guess i still dont get the hang of it...

ERROR ON LINE 14


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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

double wmodel ( double (*model)[1], double f2, double f4, double f22 , 	
		double f42, double (*data)[3], int l){


//this function does the w(theta) calculation for the model 

	double wtheta = 0 ;
	int x; 

	for (x=0 ; x < l ; ++x){
	model[x] = 1 + f2*f22*1/2*(3* pow(cos(data[x][2]),2) *-1 ) 
			+ f4*f42* 1/8*(35*pow(cos(data[x][2]),4)
			- 30 *pow(cos(data[x][2]),4) + 3);
	}
	
return (0);
}


int main () { 

//FILLING DATA ARRAYS 
// ask user for dat file
 
	ifstream dat;
	do {
		cout << "Input filename where the raw data exist-->";
		char filename [50];
		cin.getline(filename,50);
		dat.open(filename);
		if (!dat.is_open())
		cout << "File Does Not Exist!" << endl ;
	} while (!dat.is_open());

	double (*data)[3]= new double [15][3];

	int x = 0 ;
	int l = 0 ;
	double  a,b,c,d,e,f;

	while (	dat >> a >> b >> c){

		data[x][0] = a;
		data[x][1] = b;
		data[x][2] = c;

	//	cout << data[x][0] << endl; // to check
		++x;
		++l;
	}
	
	dat.close();


// fill values from giant text file that I typed by hand!! 

	ifstream table;
	do {
		cout << "Input filename where the data table exist-->";
		char file [50];
		cin.getline(file,50);
		table.open(file);
			if (!table.is_open())
			cout << "File Does Not Exist!" << endl ;
	} while (!table.is_open());


	double (*values)[6] = new double[500][6]; 
				//array from 1967 table values are:
			      // jf , ji,l1,l2,f2,f4 
	x = 0 	;
	int length = 0 ; 

	while (table >> a >> b >> c >> d >> e >> f){

		values [x][0] = a;
		values [x][1] = b;		
		values [x][2] = c;
		values [x][3] = d;
		values [x][4] = e;
		values [x][5] = f;
	//cout << values [x][0]<< "  " << values [x][5] << endl;
		++x;
		++length ;
	}		


	table.close();

	double conf2, conf4;

	for ( x = 0 ; x<length+1 ; ++x) {

	if (jm==values[x][1] and jf==values[x][0] and l2==values[x][3]){
	
		
		conf2 = values [x][4];
		conf4 = values [x][5];	
	}
	}



// find model values 

	double f2,f4;

	double (*model)[1] = new double[15][1]; 

	wmodel(model, f2, f4 , conf2, conf4, data,l);
Last edited on
In function wmodel patameter model is declared as

double (*model)[1]

that is it is a pointer to an object of type double[1].

So for example model[0] will be an array of type double[1].

In lines 12-14

1
2
3
model[x] = 1 + f2*f22*1/2*(3* pow(cos(data[x][2]),2) *-1 ) 
			+ f4*f42* 1/8*(35*pow(cos(data[x][2]),4)
			- 30 *pow(cos(data[x][2]),4) + 3);


you are trying to assign a scalar value to the array model[x]. Arrays have no the assignment operator.

That it would be more clear I will show an equivalent code to demonstrate what you are trying to do

double a[1];

a = 10.0;


The bolded statement is invalid.
ok i am slightly confused and since i have posted this i have decided to take another route.

now i am trying to pass the array in a different way. at first I didn't realize that arrays are passed by reference by default.

so now i have

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


double wmodel ( double model[], double f2, double f4, double f22 , 	
		double f42, double (*data)[3], int l){


//this function does the w(theta) calculation for the model 

	double wtheta = 0 ;
	int x; 

	for (x=0 ; x < l ; ++x){
	model[x] = 1 + f2*f22*1/2*(3* pow(cos(data[x][2]),2) *-1 ) 
			+ f4*f42* 1/8*(35*pow(cos(data[x][2]),4)
			- 30 *pow(cos(data[x][2]),4) + 3);
	}
	
return (0);
}

int main() { 

// blah blah blah 


	double model[l]; // l is a length defined by another array 
	wmodel( &model, f2, f4 , conf2, conf4, data,l);

return (0)
}


Will my array still get all the math done to it then passed back to main or do i have to send a pointer?
Last edited on
If you defined the function the following way

double wmodel ( double model[], double f2, double f4, double f22 ,
double f42, double (*data)[3], int l);

then to call it you should write

wmodel( model, f2, f4 , conf2, conf4, data, l);


ok I understand now thanks for the clarification
Topic archived. No new replies allowed.