【发布时间】:2013-10-21 18:46:31
【问题描述】:
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())
{}
}
我的编译器是 VC++ 2013 RC。
为什么explicit 与virtual 不兼容?
原因是什么?
【问题讨论】:
-
看起来像 MSVC 错误,因为在 gcc 和 clang 中工作正常。
-
您可以使用 NVI 解决此问题。
-
connect.microsoft.com/VisualStudio/feedback/details/805301/… 在 VC2017 中仍然没有修复
标签: c++ function c++11 virtual explicit