### Explain functions

Can anyone explain functions to me? I need to write a 3 function program that calculates distance and slope, I am also using a bool function so that I can tell if the slope is infinite.

Thanks!
It's a broad subject. Too broad to be explained in a 3-line forum post.

http://cplusplus.com/doc/tutorial/functions/
...but basically they are blocks of code that can be executed, and they can have a 'return' statement (unless the function is 'void') that allows them to return data back to whatever called them.
Last edited on
closed account (Dy7SLyTq)
they dont have to have a return statement and void can have one
I didn't say they had to have a return statement, and void functions cannot return any values.
closed account (Dy7SLyTq)
didnt say that. i said they can have a return statement
Can you give an example of a regular function and a boolean function?
What is a boolean function? As far as I know all functions are regular functions.
 ``1234567891011121314`` ``````void f() //regular function { cout << "Hello, world!" << endl; } int g(int a, int b) //regular function { return 7*a + b; } bool h(int x, int y, int z) //regular function { return x == 7*y && 7*x = z; }``````
Last edited on
A boolean function is a function that returns a boolean datatype.
ie:
 ``12345678910`` ``````void f(){//Returns no values } int f(){//returns integers } bool f(){//returns boolean datatype (boolean function) }``````
All three function are normal functions. There is no such thing as a "boolean function" or "void function".
It's a matter of english syntax.
If someone said to me 'boolean function', I would know they were talking about a function that returns a boolean datatype.
Sure maybe it's not the right way to say it by your standards, but really, who gives a shit.
I stand corrected:
 ``12345`` ``````struct MyClass { operator bool(); //boolean function bool f(); //normal function };``````
L B, isn't that more usually called a "boolean conversion operator", or even a "boolean operator"?

That's a genuine question - I don't claim to know the widespread terminology for it.
I was being sarcastic ;) I think they're called type cast operators.
:P
Topic archived. No new replies allowed.