What's the difference between virtual function instantiations in C++?

后端 未结 8 1893
栀梦
栀梦 2021-01-25 07:30

What\'s the difference between the following two declarations?

virtual void calculateBase() = 0;  
virtual void calculateBase();

I read the fir

8条回答
  •  深忆病人
    2021-01-25 08:01

    In Java

    virtual void calculateBase() = 0;  
    

    would be

    abstract void calculateBase();
    

    and

    virtual void calculateBase();
    

    would be

    void calculateBase();
    

    To be perfectly clear,

    void calculateBase();
    

    in C++, is "the same" as

    final void calculateBase();
    

    in Java. That is, final is "default" in C++. There is an exception to this rule however. When subclassing a class with a virtual method and reimplementing it without using the virtual keyword, the method in the subclass will not be final.

提交回复
热议问题