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

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

    I think you are mixing terms...

    virtual void x() = 0;
    

    is a pure virtual function, or abstract function. It is a virtual function without implementation. You talk about a pure abstract class, which is the c++ equivalent of an interface, about a class having only abstract functions.

    virtual void x();
    

    is a virtual function, meaning it can be redefined in derived classes, but it's not abstract, so you must provide an implementation for it.

提交回复
热议问题