C++ for Embedded · Interview question

What is function overloading and when is the choice resolved?

A strong answer

Function overloading lets multiple functions share one name as long as they differ in their parameters, number or types. The compiler performs overload resolution at compile time, choosing the best match for the argument types at each call site, then emits a direct call to that specific function. There's no runtime dispatch, tag, or indirection, it's a purely static, zero-cost mechanism. This replaces C's need for type-suffixed names (abs/labs/fabs) and lets you write, say, a write(uint8_t) and write(const uint8_t*, size_t) that callers invoke uniformly. The key constraint is that overloads must differ in parameters; you can't overload on return type alone, because the call site alone wouldn't determine which to pick.

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

Function & Operator Overloading

One name, several type-specific implementations the compiler picks for you, and giving your own types natural operators, without the runtime cost of C's void* or tagged dispatch.

More Function & Operator Overloading questions

Browse all 472 interview questions