+ 10
Actually , this question asked in interview... But i didn't get it ... The question is 👇👇
How can you make sure a C++ function can be called as e.g. void foo(int, int) but not as any other type like void foo(long, long)?
3 odpowiedzi
0
if you call foo() with variables, you make sure the variables are declared of the correct type for the foo() you want called, or you cast them to the correct type, and the compiler knows which function to call.
If you call foo() with values, like say foo(4, 5), this will call foo(int, int). If you want to call foo(long, long) you'll have to either write foo(4L, 5L) or cast them: foo((long)4, (long)5).
Here is an example I just wrote for you:
https://code.sololearn.com/cus055F1m356/?ref=app
+ 8
according to my knowledge fuction parameters can contain only pointers , characters , class objects and integer data members.....so void foo(long, long) is invalid and will cause an error.
hope this is useful for you nd btw what did they ask more? just curious to know.😁😁
+ 6
Not really sure about this, but if you didn't overload the method (in a class) or use template for arguments' type name, I guess your function would only work with the type of arguments it was specifically designed for. But I could be wrong, haven't known C++ all that well : )