虚函数可以是constexpr吗? [英] Can virtual functions be constexpr?
本文介绍了虚函数可以是constexpr吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码中的 X :: f()
这样的虚拟函数可以吗
Can virtual functions like X::f()
in the following code
struct X
{
constexpr virtual int f() const
{
return 0;
}
};
是 constexpr
?
推荐答案
从C ++ 20开始,此答案不再正确。
没有从[dcl.constexpr] / 3(7.1.5, constexpr
说明符)开始:
No. From [dcl.constexpr]/3 (7.1.5, "The constexpr
specifier"):
constexpr
函数的定义应满足以下要求:
The definition of a
constexpr
function shall satisfy the following requirements:
-不得为虚拟
这篇关于虚函数可以是constexpr吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文