R
Rahul
Hi Everyone,
I have the following code,
class B;
class A
{
public : operator B();
};
class B
{
public : B()
{
}
B(const A& ref)
{
printf("destination conversion\n");
}
B(const B& ref)
{
printf("copy constructor\n");
}
};
A:
perator B()
{
printf("source conversion\n");
return B();
}
int main()
{
A obj;
B obj1 = obj;
return(0);
}
so the output is
destination conversion.
There are actually two ways to convert from obj to obj1
1) destination conversion, constructor function of B
2) source conversion, operator function of A and then copy constructor
of B
The compiler has selected the first option, where as i expected a
ambiguity compile time error, what does the standard say for this?
I have the following code,
class B;
class A
{
public : operator B();
};
class B
{
public : B()
{
}
B(const A& ref)
{
printf("destination conversion\n");
}
B(const B& ref)
{
printf("copy constructor\n");
}
};
A:
{
printf("source conversion\n");
return B();
}
int main()
{
A obj;
B obj1 = obj;
return(0);
}
so the output is
destination conversion.
There are actually two ways to convert from obj to obj1
1) destination conversion, constructor function of B
2) source conversion, operator function of A and then copy constructor
of B
The compiler has selected the first option, where as i expected a
ambiguity compile time error, what does the standard say for this?