Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I give the correct parameters without "&" or "*" to the called method?

Tags:

c++

I am new here quite new to writing code in c++ and currently run into following problem:

I use the library wykobi which deals with geometry and solved many of my prior problems, but now I want to create a triangle using it and cant figure out how to call the required method correctly.

std::string x_str(argv[2]);
std::string y_str(argv[3]);
double x = atof(x_str.c_str());
double y = atof(y_str.c_str());

[...]

double x2;
x2 = double(orientation.direction.x)+angleRightx;
double y2;
y2 = double(orientation.direction.y)+angleRighty;
double x3;
x3 = double(orientation.direction.x)+angleLeftx;
double y3;
y3 = double(orientation.direction.y)+angleLefty;

wykobi::triangle<wykobi::Float,2> clip_boundry = wykobi::make_triangle<wykobi::Float,2>(&x,&y, &x2,&y2, &x3,&y3);
wykobi::polygon<wykobi::Float,2> clipped_polygon;
wykobi::algorithm::sutherland_hodgman_polygon_clipper<wykobi::point2d<wykobi::Float> >(clip_boundry,wykPG,clipped_polygon);

I tried something similar before creating a circle, which worked perfectly fine:

wykobi::circle<wykobi::Float> circle;
circle.x = x;
circle.y = y;
circle.radius = dist;
wykobi::polygon<wykobi::Float,2> clip_boundry = wykobi::make_polygon<wykobi::Float>(circle,100);
wykobi::polygon<wykobi::Float,2> clipped_polygon;
wykobi::algorithm::sutherland_hodgman_polygon_clipper<wykobi::point2d<wykobi::Float> >(clip_boundry,wykPG,clipped_polygon);

Now the problem on compiling is:

error: no matching function for call to 'make_triangle(double*, double*, double*, double*, double*, double*)'

When I remove the ampersands:

wykobi::triangle<wykobi::Float,2> clip_boundry = wykobi::make_triangle<wykobi::Float,2>(x,y, x2,y2, x3,y3);

The error on comiling is:

error: no matching function for call to 'make_triangle(double&, double&, double&, double&, double&, double&)'

And finally the method I call looks like this:

template<typename T> inline triangle<T,2> make_triangle(const T& x1, const T& y1, const T& x2, const T& y2, const T& x3, const T& y3);

So I wonder what do I have to change to give the correct parameters?

Thanks in advance!

like image 311
Reatus Avatar asked Apr 06 '14 10:04

Reatus


People also ask

How do you write parameters?

To specify parameters in JavaScript, we write the name of the parameter (or parameters) inside the parentheses that come after the function name. We then reference that parameter name inside the function. Now we can call that function and pass our desired value for the parameter: sayHello("Jackson"); sayHello("Mr.

What is parameter with type and without type?

Solution. Parameters are the variables in a function definition and arguments are the values that are passed to a function definition. Parameter without Type. Let us see an example of a function definition. (requires: b > =0 )

How do you write a parameter query?

Query parameters are a defined set of parameters attached to the end of a url. They are extensions of the URL that are used to help define specific content or actions based on the data being passed. To append query params to the end of a URL, a '? ' Is added followed immediately by a query parameter.


2 Answers

You have at least the following issues:

1) Mixing up double with wykobi::Float.

2) You are passing two template parameters, whereas the function only expects one.

3) Template deduction could hopefully be done here.

Try this code:

wykobi::make_triangle(x, y, x2, y2, x3, y3);

or

wykobi::make_triangle<wykobi::Float>(x, y, x2, y2, x3, y3);

or

wykobi::make_triangle<double>(x, y, x2, y2, x3, y3);

but make sure these parameters are wykobi::Float or double, respectively. Do not mix them up unless wykobi::Float is some kind of typedef.

Also, do not try passing addresses because this template function does not expect a pointer.

like image 56
lpapp Avatar answered Oct 06 '22 08:10

lpapp


The function make_triangle<wykobi::Float..() requires that you pass references to wykobi::Float, but instead, you are trying to pass variables of type double.

I don't know the library, but see if there is some explicit or implicit conversion from double to the wykobi::Float type

e.g.

wykobi::Float wx1 = x;

or

wykobi::Float wx1 = new wykobi::Float(x);

and then pass these to the make_triangle function.

Also, as per Lazlo's comment, the constant 2 does not appear valid for a template parameter - this should be a type, e.g. int.

like image 40
StuartLC Avatar answered Oct 06 '22 10:10

StuartLC