关于inline的问题

123anmanny 2007-05-26 01:40:38
在网上打到一LINUX的代码

其中有一段是这样的

inline bool bit_on(unsigned char ui,int pos){return ui&(1<<pos);}
inline void bit_setone(unsigned char& ui,int pos){ui|=1<<pos;}
inline void bit_setzero(unsigned char& ui,int pos){ui&=~(1<<pos);}

在linux下用g++编译通过,而且可以执行

但在C++ Builder 6 总报错,去掉inline也不能编译

怎么解决???
...全文
127 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
123anmanny 2007-05-26
  • 打赏
  • 举报
回复

原来前面的代码有问题

谢谢两位
结贴了
123anmanny 2007-05-26
  • 打赏
  • 举报
回复
..................


我copy songhtao(三十年孤独)的代码编译没问题。。。

我再仔细看看。。
123anmanny 2007-05-26
  • 打赏
  • 举报
回复
去掉inline,说我return处语法错误。。。。
我不懂电脑 2007-05-26
  • 打赏
  • 举报
回复
在BCB 2006下运行正常。

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include <stdio.h>

//---------------------------------------------------------------------------

#pragma argsused

inline bool bit_on(unsigned char ui,int pos){return ui&(1<<pos);}
inline void bit_setone(unsigned char& ui,int pos){ui|=1<<pos;}
inline void bit_setzero(unsigned char& ui,int pos){ui&=~(1<<pos);}

int main(int argc, char* argv[])
{
bool t;

t = bit_on('d', 5);
printf("%d\r\n", t);
scanf("%*c");

return 0;
}
//---------------------------------------------------------------------------
Y___Y 2007-05-26
  • 打赏
  • 举报
回复
我的没问题,用bool也没问题 (VC中会又警告)
123anmanny 2007-05-26
  • 打赏
  • 举报
回复
不行,在第一个inline函数处出错
提示如下:
storage class 'inline' is not allowed here

123anmanny 2007-05-26
  • 打赏
  • 举报
回复
谢谢

我先试试
Y___Y 2007-05-26
  • 打赏
  • 举报
回复
因为bool cb认为只取01两个值
Y___Y 2007-05-26
  • 打赏
  • 举报
回复
bool 换为int即可

13,870

社区成员

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

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