Why is the “virtuality” of methods implicitly propagated in C++?

前端 未结 4 1030
闹比i
闹比i 2021-01-04 08:13

What is the reason for removing the ability to stop the propagation of methods virtuality?

Let me be clearer: In C++, whether you write \"virtual void foo()\" or \"v

4条回答
  •  孤街浪徒
    2021-01-04 08:37

    C++11 added the contextual keyword final for this purpose.

    class VectIterator : public Iterator
    {
    public:
        T& next() final { ... }
        ...
    };
    
    struct Nope : VecIterator {
        T& next() { ... } // ill-formed
    };
    

提交回复
热议问题