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;
}
Printable View
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);
}
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'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.Quote:
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".