为什么我没有得到输出。我期待有趣(Test2)称为输出。由于传递的参数对于函数是不同的,因此不应存在任何冲突。
#include <iostream>
using namespace std;
class Test2
{
int y;
};
class Test
{
int x;
Test2 t2;
public:
operator Test2 () { return t2; }
operator int () { return x; }
};
void fun ( int x) { cout << "fun(int) called"; }
void fun ( Test2 t ) { cout << "fun(Test 2) called"; }
int main()
{
Test t;
fun(t);
return 0;
}
答案 0 :(得分:3)
您对fun()
的来电不明确。 t
类型为Test
,可以转换为Test2
和int
,因此fun
个实现都是候选。