Atom Posted September 16, 2015 Share Posted September 16, 2015 (edited) Hi All, I have a small piece of VEX code that will not compile. I keep getting the message that not all code paths return a value. I don't see how this is possible because there is only one return and the return is referencing a variable that is already initialized. float string_point_attribute(string attribute; int id) { string result = ""; int success = 0; string attribute_value = pointattrib(geoself(),attribute, id, success); if (success) {result = attribute_value;} return result; } What is wrong with my code? Edited September 23, 2015 by Atom Quote Link to comment Share on other sites More sharing options...
Guest mantragora Posted September 16, 2015 Share Posted September 16, 2015 (edited) Maybe it will work better if your function would return string instead of float? Edited September 16, 2015 by fântastîque Mântragorîè Quote Link to comment Share on other sites More sharing options...
MrScienceOfficer Posted September 16, 2015 Share Posted September 16, 2015 I think the problem is your implicitly casting a string to a float (I'm assuming you can do this but I've never tried), and VEX is casting result = "" to nothing rather then a value of zero, as there not really the same thing. Changing it to string result = "0", might fix that, but something like int success = 0; string attribute_value = .... if (success) return (float)attribute_value; else return 0; // or any value you know is incorrect and can test for may be a better choice, if I understood the intent of your function. Quote Link to comment Share on other sites More sharing options...
Atom Posted September 17, 2015 Author Share Posted September 17, 2015 (edited) Doh! That was it. I feel silly. I cloned this string version of the function from the float version and did not notice the type of the return value. The error message could be a little clearer. Like "Return type does not match function definition." or something... Edited September 17, 2015 by Atom Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.