简体   繁体   中英

How can I pass the value from void function in one cpp file to an other void function in an other cpp file?

I am very new to programming but i have to do this for my project.

In Visual C++ 6.0, I am trying to send the calculated value from one function to the other in a different cpp file. however, when I try to compile I get the following error :

Creating library Debug/usradd.lib and object Debug/usradd.exp addrxn.obj : error LNK2001: unresolved external symbol "float * Gamma" (?Gamma@@3PAMA) ..\\debug\\usradd.dll : fatal error LNK1120: 1 unresolved externals

How can I fix this problem? Thank you.

This is simple version of code that I tried. I like to pass Gamma matrix from addk.cpp to addrxn.cpp as shown below. Thank you.

//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;
}

The extern declaration requires a type:

extern float Gamma[23];

Your sample code:

float Gamma[1] = 2000*t;

makes no sense. Are you declaring a float array of ONE element here? You probably meant:

Gamma[1] = 2000 * t;

Anyway, your link error tells you that Gamma needs to be defined somewhere, probably in another file. Something like

float Gamma[23];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM