开发者

c++ methods in a base class

When having a base class with pure virtual methods开发者_StackOverflow社区 this makes it so that the class can not be instantiated. If I have regular methods and attributes in this base class does the derived classes still inherit those as normal?

For e.g. a getter and setter for an attribute.


Yes, all methods are inherited.


As Moron said, try it yourself. But, to put more structure around the topic...

There is interface inheritance (what methods can I call on an object?) and implementation inheritance (what code gets called when I call this method on this object?). Pure virtual methods provide interface inheritance, but not implementation inheritance. A virtual (but non-pure) method provides both, with the option to allow a derived class to provide a different implementation. A non-virtual method provides both, without the option to allow a derived class to provide a different implementation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜