Can someone point out my error in the following function definition:
Thanks!Code:float Test2 (int i, float x) { i=i+7; x=4.8+float(i); }
Can someone point out my error in the following function definition:
Thanks!Code:float Test2 (int i, float x) { i=i+7; x=4.8+float(i); }
Well, in your declaration you have
float Test2( int i, float x )
So that is a function which takes two parameters ( one integer and the second a floating point number ). Also you claim that this function will return to the caller a float. In your definition you change i and x which are temporary variables that will not get changed in your calling scope and you do not return anything. So either do one of the following things. Pass each parameter as a reference so you can modify it directly AND return void. so..
Or I guess you could add up i and x or whatever you are trying to do and store that in a variable and then use:Code:void Test2 ( int &i, float &x ) { i = i + 7; x = 4.8f + float(i); }
return ( fReturn );
in your original code. Hope this helps.
P.S. - Also you may want to use C++ sytle casting instead of C style.
static_cast<float>(i);
4.8 is a double, since the result of an expression is the type of the longest floatiest operand, you are actually assigning a double value to a float variable. This should cause a warning. The error is that the function declares a return type of float yet returns nothing.
-Prelude
My best code is written with the delete key.