Virtual/pure virtual explained

后端 未结 12 1468
暖寄归人
暖寄归人 2020-11-22 01:31

What exactly does it mean if a function is defined as virtual and is that the same as pure virtual?

12条回答
  •  青春惊慌失措
    2020-11-22 02:12

    • Virtual functions must have a definition in base class and also in derived class but not necessary, for example ToString() or toString() function is a Virtual so you can provide your own implementation by overriding it in user-defined class(es).

    • Virtual functions are declared and defined in normal class.

    • Pure virtual function must be declared ending with "= 0" and it can only be declared in abstract class.

    • An abstract class having a pure virtual function(s) cannot have a definition(s) of that pure virtual functions, so it implies that implementation must be provided in class(es) that derived from that abstract class.

提交回复
热议问题