puzzlecracker wrote:
#include<iostream>
class B; //declaration
class A{
public:
A ( ){ }
A ( B& b){
std::cout<<"A constructor is called\n";
}
};
class B{
public:
operator A() {
std::cout<<"In B, A operator is called\n";
A a;
return a;
}
};
void f (A &a ) { // FIXED if const added
std::cout<<"Ambiguity\n";
}
int main(){
B b;
f(b);
//A a=c(b);
system ("PAUSE");
return 1;
}
What do you think is wrong?
Actually there are 2 problems. My compiler tells me
"A reference that is not to 'const' cannot be bound to a non-lvalue"
After fixing that by adding the 'const' in the function signature of f()
my compiler tells me:
"Ambiguous user-defined-conversion"
But now the questions for YOU?
* Why is the const needed in the first place?
* If the const is added (and thus the first problem solved)
why and what is ambigous?
--
Karl Heinz Buchegger
kb******@gascad.at