0

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?

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Narue
0

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);
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.