Can virtual functions be constexpr?

后端 未结 3 1805
旧巷少年郎
旧巷少年郎 2021-02-13 02:46

Can virtual functions like X::f() in the following code

struct X 
{
    constexpr virtual int f() const 
    {
        return 0;
    }
};

3条回答
  •  时光取名叫无心
    2021-02-13 03:00

    This answer is no longer correct as of C++20.

    No. From [dcl.constexpr]/3 (7.1.5, "The constexpr specifier"):

    The definition of a constexpr function shall satisfy the following requirements:

    — it shall not be virtual

提交回复
热议问题