简体   繁体   中英

Passing by reference into a function, is it a promotion?

So, this crazy smart guy tested me on my knowledge of promotion and conversion. He asked this question below:

void foo(int & ri)
{
 std::cout << "do something\n";
}

int main()  
{  
 int i = 5;  
 foo(i);  
 return 0;
}

So I told him there was no conversion involved. However, he says it's promotion and that there's something involved to make it a promotion. Then he got busy and left.
Now I'm left with a burning itch and I can't find any article to help me formally with how the compiler manipulates this. May I know why is it a promotion?

You're calling a function that takes a reference to int and passing an int . There is no type promotion.

I'm sure eventually the guy you spoke with will no longer be busy. If he avoids you for the rest of your life, he was probably mistaken.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM