免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 8044 | 回复: 11
打印 上一主题 下一主题

enum bool {false,true}; 在c++里不能用了? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-05-08 15:41 |只看该作者 |倒序浏览
编译总是报错:
seqtobin.cpp:5: 错误expected identifier before bool
seqtobin.cpp:5: 错误expected unqualified-id before { token

论坛徽章:
0
2 [报告]
发表于 2008-05-08 15:47 |只看该作者
#ifndef  __cplusplus
enum bool {false,true};
#endif

论坛徽章:
0
3 [报告]
发表于 2008-05-08 16:05 |只看该作者
原帖由 flw2 于 2008-5-8 15:47 发表
#ifndef  __cplusplus
enum bool {false,true};
#endif



搞定了,谢谢
不过这好像是等于把那一行注释掉了吧?

另外为啥c++不支持了呢?有啥说法?

[ 本帖最后由 welcome008 于 2008-5-8 16:07 编辑 ]

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
4 [报告]
发表于 2008-05-08 16:08 |只看该作者
C++ 里的 bool true false 都不用你定义,人家本来就有的。

论坛徽章:
0
5 [报告]
发表于 2008-05-08 16:15 |只看该作者
原帖由 flw 于 2008-5-8 16:08 发表
C++ 里的 bool true false 都不用你定义,人家本来就有的。



知道了,谢谢!

论坛徽章:
0
6 [报告]
发表于 2008-05-11 21:58 |只看该作者
bool false true
都没有搞清楚就写C++

PS:flw2和flw是什么关系?

论坛徽章:
2
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:56:11
7 [报告]
发表于 2008-05-11 22:02 |只看该作者
如果不介意就这样吧

  1. #define bool int
  2. #define false 0
  3. #define true 1
复制代码

论坛徽章:
0
8 [报告]
发表于 2008-05-13 22:07 |只看该作者
C++有bool型

论坛徽章:
0
9 [报告]
发表于 2008-05-13 23:29 |只看该作者
原帖由 sanbiangongzi 于 2008-5-11 21:58 发表
bool false true
都没有搞清楚就写C++

PS:flw2和flw是什么关系?


没有搞清楚,所以就要努力去写,出错误,让高手指点;

觉得自己牛X就去贡献一下libstdc++

论坛徽章:
0
10 [报告]
发表于 2008-05-14 01:02 |只看该作者
用AUTOCONF提供的方法吧:

  1. /*
  2. * If stdbool.h exists and conforms to C99, define HAVE_STDBOOL_H to 1;
  3. * if the type _Bool is defined, define HAVE__BOOL to 1.
  4. * To fulfill the C99 requirements, your system.h could contain the following code:
  5. */
  6. #ifdef HAVE_STDBOOL_H
  7. # include <stdbool.h>
  8. #else
  9. # ifndef HAVE__BOOL
  10. #  ifdef __cplusplus
  11. typedef bool _Bool;
  12. #  else
  13. #   define _Bool signed char
  14. #  endif
  15. # endif
  16. # define bool _Bool
  17. # define false 0
  18. # define true 1
  19. # define __bool_true_false_are_defined 1
  20. #endif
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP