请教一个链表的问题:就是一个链表内能不能存放两种类型的数据?
时间:2010-07-19
来源:互联网
请教各位大哥大姐:
现在有一个问题,大体上就是有两个线形,直线和圆弧,对应地建两个类。然后想在一个链表或者别的容器里放进这两种数据类型,比如先放进一个直线、再放进一个圆弧,再放进一个直线。
目的是要把这些直线、圆弧等等遍例一下。一起放大10倍。
或者有别的方法?
现在有一个问题,大体上就是有两个线形,直线和圆弧,对应地建两个类。然后想在一个链表或者别的容器里放进这两种数据类型,比如先放进一个直线、再放进一个圆弧,再放进一个直线。
目的是要把这些直线、圆弧等等遍例一下。一起放大10倍。
或者有别的方法?
作者: xianliang 发布时间: 2010-07-19
Nothing is impossible
C++
class CShape{
public:
virtual double zoom(double iZoom);
class CShape *next;
};
class CShape_Line:public CShape{
.... // the Implement of Line
};
class CShape_Circle:public CShape{
.... // the implement of circle
};
....
C:
struct Shape{ //Not needed,but it will be understand easy if it existing.
int type;
};
struct Shape_Line{
int type;// =TYPE_LINE
....
void *next;
};
struct Shape_Circle{
int type; // =TYPE_CIRCLE
...
void *next;
};
C++
class CShape{
public:
virtual double zoom(double iZoom);
class CShape *next;
};
class CShape_Line:public CShape{
.... // the Implement of Line
};
class CShape_Circle:public CShape{
.... // the implement of circle
};
....
C:
struct Shape{ //Not needed,but it will be understand easy if it existing.
int type;
};
struct Shape_Line{
int type;// =TYPE_LINE
....
void *next;
};
struct Shape_Circle{
int type; // =TYPE_CIRCLE
...
void *next;
};
作者: folklore 发布时间: 2010-07-19
链表里的结构体中定义一个枚举常量,用来选择是直线还是扇形。
作者: liuyuanyang 发布时间: 2010-07-19
链表里只放数据指针和指针类型就可以了
作者: mirnshi 发布时间: 2010-07-19
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28