+ -
当前位置:首页 → 问答吧 → 请教一个链表的问题:就是一个链表内能不能存放两种类型的数据?

请教一个链表的问题:就是一个链表内能不能存放两种类型的数据?

时间:2010-07-19

来源:互联网

请教各位大哥大姐:

现在有一个问题,大体上就是有两个线形,直线和圆弧,对应地建两个类。然后想在一个链表或者别的容器里放进这两种数据类型,比如先放进一个直线、再放进一个圆弧,再放进一个直线。
目的是要把这些直线、圆弧等等遍例一下。一起放大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;
};

作者: folklore   发布时间: 2010-07-19

链表里的结构体中定义一个枚举常量,用来选择是直线还是扇形。

作者: liuyuanyang   发布时间: 2010-07-19

链表里只放数据指针和指针类型就可以了

作者: mirnshi   发布时间: 2010-07-19