int myFunc(int& myParameter)
// my code
I want myParameter to be passed by reference, I would also like it to be optional, but I accept that I can't have it all.
When I don't need to pass a value to myParameter I try this "myVal = myFunc(0)" and I get an error "incompatible types".
Am I right that I can't pass a constant to a Formal Parameter? I have to create a variable 1st "int i" & "myVal = myFunc(i)"?
By constant I assume you mean number ? you can pass a number to a function, e.g. Sleep(1000), sleeps for 1 sec.
Make myParameter a Globally defined variable then you don't have to pass it at all . . .
In my example it was a number because I specified "bool myFunc(int& myParameter)" in the function. In other functions it might be "bool myFunc2(string& myParameter)".
Do you have any idea why I got an error when I tried to call myFunc with "result = myFunc(0)", but I didn't get an error when I called it with "result = myFunc(SomeIntVariable)"
All right, I think I see some logic there. To make sure, do you agree with this conclusion?
If a function is receiving a parameter by reference, it must have a variable to put the value into to send back to the calling program. Passing a constant confuses the compiler because there's nothing to put the value into. Just having a local variable isn't good enough, it has to have someplace to pass the value back to the caller.