1 Replies - 290 Views - Last Post: 05 October 2012 - 06:38 AM Rate Topic: -----

#1 MangoTux  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 58
  • Joined: 06-April 11

getline as a function parameter?

Posted 05 October 2012 - 05:45 AM

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.
Is This A Good Question/Topic? 0
  • +

Replies To: getline as a function parameter?

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3663
  • View blog
  • Posts: 11,482
  • Joined: 05-May 12

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.

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.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1