Question

Pointers present some special problems for overload resolution.

Say for example,

void f(int* x) { ... }
void f(char* x) { ...}
int main()
{
    f(0);
}

What is wrong with calling f(0)? How can I fix the function call for f(0)?

Was it helpful?

Solution

f((int*) 0) or f((char *) 0)

But if you find yourself doing this I would take another look at your design.

OTHER TIPS

Cast it, or don't use it at all:

f((int*)0);

What is wrong with calling f(0) is the resolution is ambiguous. Both of your overloaded functions take a pointer which in this case can only be resolved via cast.

f((int*)0)

Depending on what you're trying to do here there are other options that are not ambiguous.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top