定义了一个再简单不过的类,可是编译时说我重复声明,快进来帮我看看怎么回事吧!

telescope 2003-10-16 02:07:33
我New了一个Unit,在Unit.h中定义了如下类:
class apermit
{
public:
string punit; //申请单位名称
string pdate; //申请日期
string pmaster; //单位负责人
string pfperson; //法人代表
string paddress; //申请单位地址
string ptel; //申请单位电话
string pfassets; //固定资产
string pcountw;
string pcheckw;
string pcertid;
string parea;
string pwill;
string peconom;
string pfile;
string pestab;
string pnotion;
string pndate;
string mgetdate;
string mephor;
string mefnotion;
string mdealephor;
string mdealdate;
string mpitem; //审批许可项目
string mpdind;
string mpidate;
string mpassdate;
string mpassid;
string mvalidf;
string mvalidt;
string mvkind;
string mtrans;
string memo;
string minitid;
string isnew;

apermit(void){ //构造函数
this->punit = "卫生局"; //申请单位名称
this->pdate = "2003-04-17"; //申请日期
this->pmaster = ""; //单位负责人
this->pfperson = "张三"; //法人代表
this->paddress = "明山区育人街"; //申请单位地址
this->ptel = ""; //申请单位电话
this->pfassets = ""; //固定资产
this->pcountw = "";
this->pcheckw = "";
this->pcertid = "";
this->parea = "";
this->pwill = "";
this->peconom = "";
this->pfile = "";
this->pestab = "";
this->pnotion = "";
this->pndate = "";
this->mgetdate = "";
this->mephor = "";
this->mefnotion = "";
this->mdealephor = "";
this->mdealdate = "";
this->mpitem = "这个项目没人知道"; //审批许可项目
this->mpdind = "";
this->mpidate = "";
this->mpassdate = "2003-04-07";
this->mpassid = "20031231533";
this->mvalidf = "2003-05-07";
this->mvalidt = "2004-05-06";
this->mvkind = "";
this->mtrans = "";
this->memo = "";
this->minitid = "";
this->isnew = "";
};
string yearofdt(string dt){
return dt.substr(0,3);
};
string monthofdt(string dt){
return dt.substr(5,6);
};
string dateofdt(string dt){
return dt.substr(8,9);
};
string subid(string id){
return id.substr(4,12);
};

} ;
就这么简单的一个类,编译时给出如下错误提示:
[C++ Error] thepermit.h(11): E2238 Multiple declaration for 'apermit'
[C++ Error] thepermit.h(10): E2344 Earlier declaration of 'apermit'
[C++ Error] main.cpp(38): E2285 Could not find a match for 'apermit::operator =(apermit *)'
错误行指示在类定义的第一行: class apermit{ 这一行

请高手出招纠错!!!!
...全文
42 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
fatwave 2003-10-16
  • 打赏
  • 举报
回复
再你的头文件上加上
#include <vcl.h>
就OK了,在BCB6中编译通过了
fatwave 2003-10-16
  • 打赏
  • 举报
回复
class apermit
{
public:
String punit; //申请单位名称
String pdate; //申请日期
String pmaster; //单位负责人
String pfperson; //法人代表
String paddress; //申请单位地址
String ptel; //申请单位电话
String pfassets; //固定资产
String pcountw;
String pcheckw;
String pcertid;
String parea;
String pwill;
String peconom;
String pfile;
String pestab;
String pnotion;
String pndate;
String mgetdate;
String mephor;
String mefnotion;
String mdealephor;
String mdealdate;
String mpitem; //审批许可项目
String mpdind;
String mpidate;
String mpassdate;
String mpassid;
String mvalidf;
String mvalidt;
String mvkind;
String mtrans;
String memo;
String minitid;
String isnew;

apermit(void){ //构造函数
this->punit = "卫生局"; //申请单位名称
this->pdate = "2003-04-17"; //申请日期
this->pmaster = ""; //单位负责人
this->pfperson = "张三"; //法人代表
this->paddress = "明山区育人街"; //申请单位地址
this->ptel = ""; //申请单位电话
this->pfassets = ""; //固定资产
this->pcountw = "";
this->pcheckw = "";
this->pcertid = "";
this->parea = "";
this->pwill = "";
this->peconom = "";
this->pfile = "";
this->pestab = "";
this->pnotion = "";
this->pndate = "";
this->mgetdate = "";
this->mephor = "";
this->mefnotion = "";
this->mdealephor = "";
this->mdealdate = "";
this->mpitem = "这个项目没人知道"; //审批许可项目
this->mpdind = "";
this->mpidate = "";
this->mpassdate = "2003-04-07";
this->mpassid = "20031231533";
this->mvalidf = "2003-05-07";
this->mvalidt = "2004-05-06";
this->mvkind = "";
this->mtrans = "";
this->memo = "";
this->minitid = "";
this->isnew = "";
};
String yearofdt(String dt){
return dt.SubString(0,3);
};
String monthofdt(String dt){
return dt.SubString(5,6);
};
String dateofdt(String dt){
return dt.SubString(8,9);
};
String subid(String id){
return id.SubString(4,12);
};

} ;
已经编译通过了!!
string应该是String,substr应该是SubString
GeoPhoenix 2003-10-16
  • 打赏
  • 举报
回复
你可能多次引用了这个定义,具体的程序没见到,建议如下
#ifndef _YOUR_CLASS
#define _YOUR_CLASS

//你的类代码

#endif
单独存成一个h文件,看行否?
zxy_net 2003-10-16
  • 打赏
  • 举报
回复
你写的类真有点另类,把构造函数在类中声明一下,构造函数内容写在类的实现模块里。建议把成员函数的声明与实现分开写(纯属个人意见)

13,825

社区成员

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

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