Why does the following code not compile:
struct X
{
struct B;
struct A
{
int dummy;
operator B();
};
struct B
{
int dummy;
};
};
X::A::operator B()
{
B b;
return b.dummy = dummy, b;
}
My MSVC++ 2017 compiler says:
error C2833: 'operator B' is not a recognized operator or type
The only possible reason of this error is that struct B is not defined-yet at the point when struct A is being defined. Since the code does not seem the be buggy, my conclusion is that you have found a compiler bug.
Even though B should be looked up in the scope of X as the user defined conversion operator is being defined, MSVC seems to bungle it up.
You can give it hand by fully qualifying it:
X::A::operator X::B()
{
B b;
return b.dummy = dummy, b;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With