Changing return types

Lets say I have this function:
1
2
3
4
??? fn(int n)
{
   // ....
}



If n is negative, I want it to return a double. If it is positive or 0, I want it to return an int.

This is a math function, so the value is just going to be multiplied or added immedietly. I won't need to know what the return type is beforehand.

I have tried doing:

1
2
3
4
5
6
7
8
9
double fn(int n)
{
   // ...
}

int fn(unsigned int n)
{
   // ...
}


but "Cannot evaluate function -- may be inlined" for any input.

Ideas? Keywords I don't know about?
Im not sure if this will do what you want, but just make one function that returns double.

If you need to store it in an int, it will just lose the decimal. *Note that it will NOT round.
....facepalm. Yes, that will work :D

But now I'm just curious. Is this possible (actually sending different types) in any way shape or form?
You can use a template, with if-else conditions calling the specific types after the input of n.
Topic archived. No new replies allowed.