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; }
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 02:23 PM.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
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.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
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".
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens