[原]missing ';' before 'namesapce'错误的解决

本文详细解析了C++编译错误missing ';' before 'namespace'的成因,通过案例分析帮助开发者识别并修复相关问题。重点讨论了包含文件中可能存在的错误及其对后续编译的影响,并提供了排查和解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

作者:朱金灿

来源:http://blog.youkuaiyun.com/clever101

 

       上午开发时出现一个编译错误:missing ';' before 'namesapce',我仔细检查了出错的那句代码,感觉任何没有问题。删掉再重新输入也依然出现这个问题。上网查了下资料,找到了答案:

 

          This can happenwhen one include file has an error (or missing semicolon) at the end of thefile and that file is included immediately before another. The error that isgenerated indicates that there is a problem in the second include file ratherthan the first. So as a starting point, make sure that, if you have a filethat's included before Time.h, that is doesn't have any errors in it.

          Pasting thecontent of your .h and .cpp files would certainly be helpful rather than justthe error message.

 

        上面是说某个包含的头文件有一个错误(可能是缺少一个分号)。看到这里,我想到刚刚新建的一个类的头文件声明是不是缺少分号呢?一去检查,发现果然缺少分号。该错误的诡异之处在于编译器并不把错误提示在缺少分号的那个头文件,而是其它头文件,结果就是导致了让人找了很久也百思不得其解。我的编译环境是VS 2005+sp1, Win XP + sp3。

 

参考文献:


1. ErrorC2143 (missing ; before namespace) in MS VC include


作者:clever101 发表于2012-3-1 18:11:03 原文链接
阅读:46 评论:0 查看评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值