I am creating a structure as a data type What i basically want is to store the data which is line co-ordinates but when i pass two lines to find their distance and in arguments I pass the element of an array which is simple and the receiving argument is * how to resolve it.
This is the structure.
struct line_coordinates{
double x1,y1,x2,y2;
};
Here I am creating the array of a structure line_coordinates* array_line; Now calling the getdistance() and passing arguments
void initlize(vector<Vec2f> line1){
lines=line1;
array_line=new line_coordinates[lines.size()];
cout<<getdistance(array_line[0],array_line[1]);
double getdistance(line_coordinates *line1,line_coordinates *line2 )
{
double midpointx1,midpointy1,midpointx2,midpointy2;
midpointx1 =((line1->x1+line1->x2)/2);
midpointy1=((line1->y1+line1->y2)/2);
midpointx2 =((line2->x1+line2->x2)/2);
midpointy2=((line2->y1+line2->y2)/2);
double dist = sqrt(pow(midpointx2 - midpointx1, 2) + pow(midpointy2 - midpointy1, 2));
return dist;
}
Let's see, array_line
is of type line_coordinates*
, that means that array_line[i]
is of a type convertible to line_coordinates const&
, which means that you should pass it by reference or by value instead:
double getdistance(line_coordinates const& line1,line_coordinates const& line2)
// ^^^^^^ ^^^^^^
Oh and by the way, please use std::vector
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments