P
puzzlecracker
back to the same question: why in this code copy contor in A is called
instead of to flag the AMBIGUITY????? I have tried different compilers
for that.
#include<iostream>
class B; //declaration
class A{
public:
A ( ){ }
A ( const B& b){ /////////////////////////////////////
std::cout<<"A constructor is called\n";
}
};
class B{
public:
operator A() const { //////////////////////////
std::cout<<"In B, A operator is called\n";
A a;
return a;
}
};
void f (const A& a)
{
std::cout<<"Ambiguity\n";
}
int main(){
B b;
f(b);
return 0;
}
instead of to flag the AMBIGUITY????? I have tried different compilers
for that.
#include<iostream>
class B; //declaration
class A{
public:
A ( ){ }
A ( const B& b){ /////////////////////////////////////
std::cout<<"A constructor is called\n";
}
};
class B{
public:
operator A() const { //////////////////////////
std::cout<<"In B, A operator is called\n";
A a;
return a;
}
};
void f (const A& a)
{
std::cout<<"Ambiguity\n";
}
int main(){
B b;
f(b);
return 0;
}