error C2146: 语法错误: 缺少“;”(在标识符“m_tTimer”的前面) error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int

本文介绍了在Visual Studio 2013中遇到的C++编译错误案例,包括缺少分号和类型说明符的问题,并探讨了可能的原因,如头文件相互包含及未正确包含所需的头文件。

1>e:\visual studio 2013files\projects\muke\t18_友元类\t18_友元类\match.h(11): error C2146: 语法错误: 缺少“;”(在标识符“m_tTimer”的前面)
1>e:\visual studio 2013files\projects\muke\t18_友元类\t18_友元类\match.h(11): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1> Time.cpp
1>e:\visual studio 2013files\projects\muke\t18_友元类\t18_友元类\match.h(11): error C2146: 语法错误: 缺少“;”(在标识符“m_tTimer”的前面)
1>e:\visual studio 2013files\projects\muke\t18_友元类\t18_友元类\match.h(11): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int

出现上述错误,可能的原因有:

  1. 如果存在两个类的头文件apple.h和boy.h,在apple.h中包含了boy类的头文件(即apple.h中存在 #include“boy.h”);而在boy.h中又存在#include“apple.h”,且这两个类中的某一个类又使用了另一个类的对象。
  2. 没有包含要定义的头文件。
我发现,只要你给的代码就没有一次能通过编译的,只要给代码编译错误必然一大堆! procedure GlobalExceptionHandler(Sender: TObject; E: Exception); begin // 记录异常到日志文件 AssignFile(LogFile, 'crash.log'); if not FileExists('crash.log') then Rewrite(LogFile) else Append(LogFile); Writeln(LogFile, '[' + DateTimeToStr(Now) + '] '); Writeln(LogFile, 'Exception class: ', E.ClassName); Writeln(LogFile, 'Exception message: ', E.Message); CloseFile(LogFile); // 显示错误信息 MessageBox(0, PChar('程序发生致命错误:' + E.Message), '错误', MB_ICONERROR); end; begin Application.Initialize; // Application.MainFormOnTaskbar := True; Application.OnException := GlobalExceptionHandler; // 设置全局异常处理 try Application.CreateForm(TMainForm, MainForm); except on E: Exception do begin // 创建主窗体失败,记录日志 AssignFile(LogFile, 'crash.log'); Append(LogFile); Writeln(LogFile, '[' + DateTimeToStr(Now) + '] 创建主窗体失败'); Writeln(LogFile, 'Exception class: ', E.ClassName); Writeln(LogFile, 'Exception message: ', E.Message); CloseFile(LogFile); MessageBox(0, PChar('创建主窗体失败:' + E.Message), '错误', MB_ICONERROR); Exit; end; end; [dcc32 Error] Project_HIDComm.dpr(13): E2003 Undeclared identifier: 'Exception' [dcc32 Error] Project_HIDComm.dpr(17): E2003 Undeclared identifier: 'FileExists' [dcc32 Error] Project_HIDComm.dpr(21): E2003 Undeclared identifier: 'DateTimeToStr' [dcc32 Error] Project_HIDComm.dpr(21): E2003 Undeclared identifier: 'Now' [dcc32 Error] Project_HIDComm.dpr(22): E2029 ',' or ')' expected but identifier 'ClassName' found [dcc32 Error] Project_HIDComm.dpr(33): E2009 Incompatible types: 'method pointer and regular procedure' [dcc32 Error] Project_HIDComm.dpr(38): E2005 'Exception' is not a type identifier [dcc32 Error] Project_HIDComm.dpr(43): E2003 Undeclared identifier: 'DateTimeToStr' [dcc32 Error] Project_HIDComm.dpr(43): E2003 Undeclared identifier: 'Now' [dcc32 Error] Project_HIDComm.dpr(44): E2029 ',' or ')' expected but identifier 'ClassName' found [dcc32 Error] Project_HIDComm.dpr(50): E2029 '.' expected but ';' found
最新发布
10-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值