Pure virtual function with implementation

前端 未结 9 1989
长发绾君心
长发绾君心 2020-11-22 10:10

My basic understanding is that there is no implementation for a pure virtual function, however, I was told there might be implementation for pure virtual function.

9条回答
  •  情歌与酒
    2020-11-22 11:05

    Yes this is correct. In your example, classes that derive from A inherit both the interface f() and a default implementation. But you force derived classes to implement the method f() (even if it is only to call the default implementation provided by A).

    Scott Meyers discusses this in Effective C++ (2nd Edition) Item #36 Differentiate between inheritance of interface and inheritance of implementation. The item number may have changed in the latest edition.

提交回复
热议问题