我刚刚继承了一些C++代码,这些代码写得不好用一个cpp文件,其中包含main和一堆其他函数.还有一些.h文件包含类及其函数定义.
到目前为止,该程序是使用该命令编译的g++ main.cpp.现在我已经将类.h和.cpp文件分开了,我需要使用makefile还是我仍然可以使用g++ main.cpp命令?
我在头文件和源文件中有此代码。这是代码的小片段。这是来自.cpp文件。
int sample(Cdf* cdf)
{
//double RandomUniform();
double r = RandomUniform(); //code that is causing the error
for (int j = 0; j < cdf->n; j++)
if (r < cdf->vals[j])
return cdf->ids[j];
// return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是从.c文件:
double RandomUniform(void)
{
double uni;
/* Make sure the initialisation routine has been called */
if (!test)
RandomInitialise(1802,9373);
uni = u[i97-1] - u[j97-1];
if (uni <= 0.0)
uni++;
u[i97-1] = uni;
i97--;
// ...
}
Run Code Online (Sandbox Code Playgroud)
这是从我的头文件
void RandomInitialise(int,int);
double …Run Code Online (Sandbox Code Playgroud)