#include <iostream>
using namespace std;
struct A {
A(int i) {
cout << "1 args" << endl;
}
A(int i, int j) {
cout << "2 args" << endl;
}
};
void foo(int i) {
cout << "1 args" << endl;
}
void foo(int i, int j) {
cout << "2 args" << endl;
}
int main() {
int i, j;
A(i, j);
(A)(i, j);
foo(i, j);
(foo)(i, j);
}
输出:构造的在C A二义性++
2 args
1 args
2 args
2 args
我知道结果 “1个ARGS” 是因为 “(I,J)” 作为 “J” 进行评价。
但考虑构造函数的区别的原因也是函数?
构造函数不是你解释意义上的函数。 '(A)(i,j)'是一个类型转换,而不是'''构造函数的显式调用。你可以达到与'static_cast (i,j)'相同的效果。 – Peter