I have the following C++ code:

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

I understand that this has a problem interpreting which function to call. I also think I can get rid of this problem by giving it two different names to the functions, but the correction I can make are only on the function call. Should I just call the function twice making distinction on what I am sending? If not, what would be the best way to change the function call without modifying the functions themselves?

Cast it:

#include <iostream>

void f(int* x) { std::cout<<"int*\n"; }
void f(char* x) { std::cout<<"char*\n"; }

int main()
{
  f((char*)0);
  f((int*)0);
  //f(0);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.