typedef的问题

yumangmang 2008-04-02 08:42:04
大家好!
我希望设计一个通用的类,就是不管类里面的数组的类型是什么都可以正常工作,所以前面用typedef来做一个替换,开始的时候替换的是unsigned long类型是没有问题的,但是后来我自己定义了一个football的结构类型就不行了,后来看网上说typedef后面只能替换已有的类型,不能替换自定义的类型,不知道是不是这样,如果是这样的话,那我该怎么办呢?

#ifndef LISTCLASS_H_
#define LISTCLASS_H_

typedef football ITEM;//这个行不通

class thelist
{
private:
enum{MAX = 10};
ITEM items[MAX];
unsigned int top;
unsigned int num;
public:
thelist();
bool add(const ITEM it);
bool isempty()const;
bool isfull()const;
void visit(void (*pf)(ITEM &));
void visit(void (*pf)(ITEM &),unsigned int n);
void show()const;
};

#endif
...全文
37 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yumangmang 2008-04-03
  • 打赏
  • 举报
回复
呵呵,谢谢楼上的各位,看来我还是对include没搞熟练阿。
ccrun.com 2008-04-02
  • 打赏
  • 举报
回复
可以替换的,只不过,你得让编译器找到被替换类型的原始声明
typedef int football;
typedef football wokao;

void __fastcall TForm1::Button1Click(TObject *Sender)
{
wokao i;
i = 1;
ShowMessage(i);
}
  • 打赏
  • 举报
回复
当然可以替换了,只不过你得在前面写上你的类型声明;

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧