+ 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)?

13th Jan 2018, 4:40 PM
Hope
Hope - avatar
3 Answers
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
14th Jan 2018, 10:16 AM
lion
lion - avatar
+ 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.šŸ˜šŸ˜
13th Jan 2018, 6:48 PM
adnan
adnan - avatar
+ 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 : )
14th Jan 2018, 8:35 AM
Ipang