当函数重载被用于哪个函数时,它们实际上去......?
void print(int); //print 1
void print(char *); //print 2
void set (int *); //set 1
void set (const char *); //set 2
int main() {
print (0); //Which print?
set (0); //Which set?
2
.. 的类型是什么?它是 int
还是 short
...例如...在下面的代码中,f 被调用...对于 f(2)
void f(int, double = 0.0); //f1
void f(short); //f2
最佳答案
print (0); //Which print?
print(int)
因为 0
是 int
。这是完全匹配 — 无需转换。
set (0); //Which set
不明确,因为 0
(即 int
)可以转换为任何类型的空指针。所以这段代码会导致编译错误。
And what is the type of 2..? Is it int or short
它是int
。如果没有任何后缀,则所有整数文字都是int
类型。
For eg... in the following code which f is called.. for f(2)
现在你应该自己弄明白了。
关于c++ - C++中的函数重载与数字的数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21737054/