0

I am studying function overloading and I have read that promotion takes precedence over conversion. What is promotion and how does it differ from conversion?

For example:

void func(int); //function number 1
void func(double); //function number 2
char a;
func(a); // which function will be called, 1 or 2?

1 Answer 1

1

Someone can probably explain this better than me, but I can give example.

Promotions are from types like char to short, or to int, or long (etc). Conversions are things like char to double or double to bool.

In your example, when calling func, there's two options: func(int) and func(double). Since char to double is a conversion, but char to int is a promotion, then func(int) will be called.

I would suggest reading [conv] of the standard.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.