搜索
查看: 1281|回复: 1
打印 上一主题 下一主题

如何让头文件编译时执行一个定义在其他头文件中的函数

[复制链接]
跳转到指定楼层
楼主
发表于 2013-6-21 13:14:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
5啊哈币
如题
[code=Cpp width=740px]#ifndef _RANT_H_
#define _RANT_H_
#include <stdlib.h>
#include <time.h>
srand((unsigned)(time(NULL));
float ranflt(float d,float b)
{
e:;
float a=rand()%(int)(100000*b);
a/=100000;
if(rand()%2)
a=-a;
if(a<d)
goto e;
return a;

}
int ranint(int p,int q)
{ int r=rand()%(q+1);
while(r<p)
r=rand()%q;
return r;
}
#endif[/code]
这样的话,编译器会将
srand((unsigned)(time(NULL));
当做一个函数的声明

最佳答案

查看完整内容

写个class,放在ctor里面好了……
沙发
发表于 2013-6-21 13:14:36 | 只看该作者
写个class,放在ctor里面好了……
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广播台
特别关注
快速回复 返回顶部 返回列表