[英]how can I use a function from one cpp file in another cpp file?
[英]How can I pass the value from void function in one cpp file to an other void function in an other cpp file?
我對編程很陌生,但我必須為我的項目這樣做。
在 Visual C++ 6.0 中,我試圖將計算值從一個函數發送到另一個 cpp 文件中的另一個函數。 但是,當我嘗試編譯時,出現以下錯誤:
創建庫 Debug/usradd.lib 和對象 Debug/usradd.exp addrxn.obj : error LNK2001: unresolved external symbol "float * Gamma" (?Gamma@@3PAMA) ..\\debug\\usradd.dll:fatal error LNK1120: 1未解決的外部
我該如何解決這個問題? 謝謝你。
這是我嘗試過的簡單代碼版本。 我喜歡將 Gamma 矩陣從 addk.cpp 傳遞到 addrxn.cpp,如下所示。 謝謝你。
//callccx.h
//declare "Gamma" array
extern Gamma[23];
//addk.cpp
void addk(float *y, float *x, double t, double p, float *xkv)
{
float Gamma[1] = 2000*t;
.
.
.
float Gamma[23] = 2300*t;
for(int i=0;int<23;i++)
{
xkv[i] = 200*t/p*Gamma[i];
}
return;
}
//addrxn.cpp
int addrxn0(const int nUopID, const int nRxnID, const int nComponents,
const double fTemperature, const double fPressure, const double fRPM,
const double fBetaFac, const double fFreqFac, const double fExpActE,
const double *C, const double *Pi, const double *fStoich,
const double *fExponent, const double *fAdsFac, const double *fAdsE,
const double *fAdsExp, double *pRateForm)
{
//Arhenius
double rate=fExpActE*fFreqFac*Gamma[1]/Gamma[2];
int iComp;
for(iComp=0;iComp<nComponents;iComp++)
{
if(fStoich[iComp] < 0)
{ //This is a reactant.
if(fExponent[iComp] == 0.0)
rate*=pow(C[iComp], -fStoich[iComp]); //Use stoich as exponent
else
rate*=pow(C[iComp], fExponent[iComp]); //Use exponent as given
}
}
//Final rate of formation
(*pRateForm)=rate*
return 0;
}
extern
聲明需要一個類型:
extern float Gamma[23];
您的示例代碼:
float Gamma[1] = 2000*t;
沒有意義。 您是否在這里聲明了一個包含 ONE 元素的浮點數組? 你可能的意思是:
Gamma[1] = 2000 * t;
無論如何,您的鏈接錯誤告訴您Gamma
需要在某處定義,可能在另一個文件中。 就像是
float Gamma[23];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.