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

后端 未结 8 1986
栀梦
栀梦 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 07:51

    virtual void calculateBase() = 0;

    The first function is Pure virtual function where the implementation can not be done in the class and it act as pure abstract class or Interface class. The concrete implementation should be done or overriden in subclass. It act as interface class to its derived classes.

    virtual void calculateBase();

    This function is virtual function where the implementation (default) can be done in the base class. But, the derived class must be overriden its own imeplementation.

提交回复
热议问题