开关结构+ cpp [英] switch structure + cpp

查看:48
本文介绍了开关结构+ cpp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我想让代码在具有开关结构的c ++中绘制圆形,点,线和椭圆形. C ++作为一种面向对象的语言.

您应该创建一个像Shape这样的抽象基类,并派生LineEllipseRectangle等类.最好不要在层次结构中包含Point,因为它不能具有相同的呈现方式.而是创建一个结构Location,并使它的实例成为Shape的成员.不要包含CircleSquare,因为它们在EllipseRectangle的特殊情况下会更好地工作,只需添加特殊的构造函数和/或工厂方法即可.

…我觉得我在浪费时间.您真正需要的是阅读一些有关C ++和OOP的基本手册.

—SA


Hello,
I want the codes to draw circle, dot, line and ellipse in c++ with switch structure, please.

解决方案

Doing it with switch is a huge abuse of C++ as an object-oriented language.

You should create an abstract base class like Shape and derive the classes Line, Ellipse, Rectangle and more. Better don''t include Point in the hierarchy as it cannot have the same rendering. Instead, create a structure Location and make an instance of it a member of Shape. Don''t include Circle and Square as they would work much better as special cases of Ellipse and Rectangle, just add special constructors and/or factory methods.

…I feel I''m wasting my time. What you really need is to read some elementary manuals on C++ and OOP.

—SA


这篇关于开关结构+ cpp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆