Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I wrote the following code for calculating the euclidian distance between 2 arrays:
C++
double dist(double x[3], double y[3])
{
	double Sum;
	double distance;
	for(int i=0;i<3;i++)
	{
		Sum = Sum + pow((x[i]-y[i]),2.0);
		distance = sqrt(Sum);
	}
	return distance;
}


When I try to assign the distance to another array
double asd[3]=dist(brick_v[3],metal_v[3]);
the compiler gives me the following error error C2664: 'dist' : cannot convert parameter 1 from 'double' to 'double []'.

Can anyone point out what I did wrong?

Thanks.
Posted

Your dist() function is expecting an array of 3 doubles. Assuming your input variables are declared like so:

double brick_v[3];
double metal_v[3];


You should call dist() like so:

dist(brick_v,metal_v);


Note that the return value of dist() is a double (one number) and not an array of doubles, so your variable asd should be filled like this:

double asd = dist(brick_v,metal_v);
 
Share this answer
 
v2
Comments
Alex_baner 14-Sep-11 11:55am    
Thanks a lot
dist takes two double arrays of length 3, you're passing two doubles, assuming brick_v is an array of double then brick_v[3] is a double
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900