Why can't an object of abstract class be created?

前端 未结 16 933
误落风尘
误落风尘 2020-12-02 21:25

Here is a scenario in my mind and I have googled, Binged it a lot but got the answer like

\"Abstract class has not implemented method so, we cant create the object\

16条回答
  •  不思量自难忘°
    2020-12-02 21:40

    I don't agree with the accepted answer. The reason is that we can have body for pure virtual function.

    The answer is that :

    When we create a pure virtual function in the class, we reserve a slot for a function in the VTABLE, but doesn't put any address in that slot. Hence the VTABLE will be incomplete. As the VTABLE for Abstract class is incomplete, hence the compiler will not let the creation of object for such class and will display an error message whenever you try to do so.

提交回复
热议问题