struct A
{
// error C2216: 'explicit' cannot be used with 'virtual'
virtual explicit operator bool() const
{
return true;
}
};
struct B : A
{
// error C2216: 'explicit' cannot be used with 'override'
explicit operator bool() const override
{
return false;
}
};
int main()
{
if (A())
{}
if (B())
{}
}
My compiler is VC++ 2013 RC.
Why is explicit
not compatible with virtual
?
What's the rationale?
Looks like a bug, since the following quotes prove that they are indeed compatible, and I couldn't find anything to disallow it.
2) A conversion function may be
explicit
[...]
[...]
5) Conversion functions can bevirtual
.
and
5) The
virtual
specifier shall be used only in the initial declaration of a non-static class member function; see 10.3.
6) Theexplicit
specifier shall be used only in the declaration of a constructor or conversion function within its class definition; see 12.3.1 and 12.3.2.
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