相关疑难解决方法(0)

最终虚拟功能的重点是什么?

维基百科在C++ 11 final修饰符上有以下示例:

struct Base2 {
    virtual void f() final;
};

struct Derived2 : Base2 {
    void f(); // ill-formed because the virtual function Base2::f has been marked final
};
Run Code Online (Sandbox Code Playgroud)

我不明白引入虚拟功能并立即将其标记为最终功能.这只是一个不好的例子,还是有更多的东西?

c++ inheritance virtual-functions final c++11

53
推荐指数
6
解决办法
2万
查看次数

使用final类说明符时,最终函数说明符是多余的吗?

是否有任何理由指定一个函数,因为final该类已经final?或者这是多余的?

class B
{
public:
    virtual void f();
};

class D final : public B
{
public:
    virtual void f() final; // Redundant final?
};
Run Code Online (Sandbox Code Playgroud)

说一下这是一个很好的经验法则:从创建整个类开始final,只有final在需要派生类和/或覆盖特定函数时才切换到创建单独的函数?

c++ c++11

6
推荐指数
1
解决办法
577
查看次数

标签 统计

c++ ×2

c++11 ×2

final ×1

inheritance ×1

virtual-functions ×1