I'm taking a C++ class, and one of my classmates mentioned that there was a way to get the user's input at the same time as calling a method, but he forgot how to do it. I'm just wondering how that's written (if possible), and if it's more/less practical than sending regular input into a method.
getline as a function parameter?
Page 1 of 11 Replies - 129 Views - Last Post: 05 October 2012 - 06:38 AM
Replies To: getline as a function parameter?
#2
Re: getline as a function parameter?
Posted 05 October 2012 - 06:38 AM
I doubt that it is happening simultaneously. What is happening is that the computer is evaluating the parameters that need to go into the callstack prior to the function call. If a parameter involves a function call, then that function will be called as part of the evaluation.
How useful it is depends on whether in makes your code clearer and easier to understand. In the above example, it's pretty obvious what is happening because there is a single parameter. But if you have a lot of parameters, the order of evaluation of the parameters is undefined and up to the compiler.
void print(char ch)
{
putchar(ch);
}
int main()
{
print(getchar());
return 0;
}
How useful it is depends on whether in makes your code clearer and easier to understand. In the above example, it's pretty obvious what is happening because there is a single parameter. But if you have a lot of parameters, the order of evaluation of the parameters is undefined and up to the compiler.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|