Distinguish between an int and a char?

I have a function which accepts an int or a character. The other is set to a default.

float goTo(char character='\0', int line=0);

My problem is that if I were to enter
goTo('A');
I would get the same result if I were to put
goTo(65);
because it accepts the 65 as the character A.

So how can I make it so if I enter a number, it puts it in the int, and if I enter a character, it puts it in the character?

The function works by which one is true, that is why their defaults are 0 and '\0'.

Thanks!
Last edited on
If you just have the char parameter it would accept also integers:
1
2
3
// float goTo(char character);
goTo('A'); //OK
goTo(65); //OK 
That's the problem! I don't want the char to accepts ints.

The function takes you to either a line in a file, or a line starting with the character. Thus, I need to know if I make it go to a certain line, or if I'm simply going to a line starting with a character.

That is why there is both.
Overload the function:
1
2
3
4
5
6
7
8
9
float goTo(char character)
{
   //some code
}

float goTo(int line)
{
   //some other code
}
overload your function one with a char argument (for passing char literals) and the other with int argument for numbers.

Try calling these functions with different parameters.
1
2
void f(char) { cout << "char\n"; }
void f(int) { cout << "int\n"; }
Worked like a charm!
Topic archived. No new replies allowed.