Clip
Clip

Reputation: 3078

Pass double by reference C++

Given

double skewAngle;

How could I pass this variable into a function and have it modified without returning the value?

My current function declaration looks like this:

Mat findCard(Mat& baseImage, double *angle)

When I try findCard(baseImage, *skewAngle);

I get a deceleration not found, can anyone show me how I can do this?

Upvotes: 2

Views: 9669

Answers (2)

songyuanyao
songyuanyao

Reputation: 172924

You're passing the variable by pointer, not by reference, so you need to pass the address of the variable to the function, such as:

findCard(baseImage, &skewAngle);

If you want to pass it by reference, you need to change your function declaration to:

Mat findCard(Mat& baseImage, double& angle)

and then you can pass the variable directly to the function, such as:

findCard(baseImage, skewAngle);

Upvotes: 4

haccks
haccks

Reputation: 106012

Your function call is wrong. You need to pass the address of the variable skewAngle as the second parameter of your function expects double *. Call it as

findCard(baseImage, &skewAngle);   

Note that, as per your function declaration, only first parameter can be passed by reference. second parameter has to passed by pointer.

Upvotes: 2

Related Questions