I'm trying to use the following in a program, but seem to be getting an error. Any ideas why?
Code:bool greater (int a, int b) { if (a > b) return true; }
This is a discussion on Function Help within the C++ Programming forums, part of the General Programming Boards category; I'm trying to use the following in a program, but seem to be getting an error. Any ideas why? Code: ...
I'm trying to use the following in a program, but seem to be getting an error. Any ideas why?
Code:bool greater (int a, int b) { if (a > b) return true; }
Functions need to return a value. Currently your function only returns a value when the test is true. You still need to return a false value if the test is false. Change it to this:
Code:bool greater(int a, int b) { return (a > b); }
Last edited by hk_mp5kpdw; 03-01-2006 at 01:23 PM.
I used to be an adventurer like you... then I took an arrow to the knee.
My compilier says there's a linker error...
There is a problem with the function which I've noted and corrected above.
A nit... compilers show compiler errors, linkers show linker errors.
Don't know what could be causing the linker error... there is a templated function object called greater defined in the <functional> header but I don't think that would cause a problem (maybe?).
Maybe you could show some more of your code if it isn't too big.
I used to be an adventurer like you... then I took an arrow to the knee.
I'm sorry, I didn't see the re-written code. Thanks!
I had edited my post while you were making your post... it was a timing issue.Originally Posted by boxsterh
As to the error, just considering your original function's code, the compiler (not linker) should have generated an error (or is it a warning?) that said something along the lines of "not all control paths return a value".
I used to be an adventurer like you... then I took an arrow to the knee.