So I have a class made in c++ and need to convert it into vb.net but I got problem converting a certain part of a function.
void deg_min_sec2decimal(double deg, double min, double sec, double& dec_deg)
{
dec_deg = (deg+min/60.0+sec/3600.0);
}
What type of variable is "double&", I know a double but what's with the "&"? It isn't " double &dec_deg" so it isn't an adres (pointers ect.)?
and how would i convert that to vb.net?
Grtz
It's a reference. That means that whatever you set the value to inside the function, the original variable that was passed in from outside will have that value.
You can convert this to VB by using ByRef
or making the function return the result of that expression instead of taking the double&
, and setting the variable you would have passed in to the result of the function.
So if you had this before:
double retval;
deg_min_sec2decimal(something, something2, something3, retval);
You'd change that to
Dim retval = deg_min_sec2decimal(something, something2, something3)
(I don't know VB so that syntax might be wrong, but you get the idea.)
I'd go with the latter because returning things through arguments is usually only used when you need more than one return value, and that function isn't even returning anything.
double& is just a double passed by reference. In VB.NET, it would be declared ByRef dec_deg as Double
.
EDIT: However, I would recommend instead of using a void
function to set a value by reference, just change the return type to double
and return the expression instead of having to pass a variable by reference.
double&
is a reference to a double. This means in that case that the function can change the value of the passed parameter.
In VB, you do this by ByRef
parameters:Sub deg_min_sec2decimal(deg as Double, min as Double, sec as Double, ByRef dec_deg as Double)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With