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

后端 未结 8 1901
栀梦
栀梦 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:57

    First one is called a pure virtual function. Normally pure virtual functions will not have any implementation and you can not create a instance of a class containing a pure virtual function.

    Second one is a virtual function (i.e. a 'normal' virtual function). A class provides the implementation for this function, but its derived class can override this implementation by providing its own implementation for this method.

提交回复
热议问题