As a lazy programmer, I’m all about not rewriting code in all those subclasses I made. Consider the function draw for the various Shapes. Every time I draw, I should be sure I’m using the Shape’s color. I don’t want Circle::draw, Rectangle::draw, etc. to all have to do this separately – if nothing else, I’ll forget. So let’s adapt Shape so it can remember:

错误:搜索内容不能为空,请输入英文关键词
错误:关键词超出字数限制,请精简
高级检索

Virtual Functions and Multiple Inheritance

  • Will Briggs

摘要

As a lazy programmer, I’m all about not rewriting code in all those subclasses I made. Consider the function draw for the various Shapes. Every time I draw, I should be sure I’m using the Shape’s color. I don’t want Circle::draw, Rectangle::draw, etc. to all have to do this separately – if nothing else, I’ll forget. So let’s adapt Shape so it can remember: