I am trying to declare an array inside a structure; however, I am having trouble calling it properly. Any help would be appreciated.
I tried it in two different ways: first gives compilation error and second gives linking error. I did extensive search to fix the compilation error myself; but, I could not figure out. Hence, I need some help
I defined the structure as:
struct stPulse_Cal{
static sSample asArbSqShape[4000];
double dNormalizedAmplitudeIntegral;
};
Approach 1: Here sSample is another structure defined in third party library and this is how I am using it:
int i;
static sSample asArbSqShape1[4000];
double placeholder[4000];
double dNormalizedAmplitudeIntegral1=0.0;
stPulse_Cal oPulse_Cal1;
// Define the pulse shape (just a trapezoid)
for (i=0; i < 4000; i++)
{
asArbSqShape1[i].flAbs = 0.01*i;
asArbSqShape1[i].flPha = 0.0;
placeholder[i] = 0.01*i;
dNormalizedAmplitudeIntegral1 += placeholder[i];
}
oPulse_Cal1.asArbSqShape = asArbSqShape1; // Line 130
oPulse_Cal1.dNormalizedAmplitudeIntegral = dNormalizedAmplitudeIntegral1;
I get the following error: (line no 130 marked in previous code snippet)
SpecialPulses.cpp(130) : error C2106: '=' : left operand must be l-value
Approach 2: When I tried to do something like this for the call part:
int i;
static sSample asArbSqShape1[4000];
double placeholder[4000];
double dNormalizedAmplitudeIntegral1=0.0;
stPulse_Cal oPulse_Cal1;
// Define the pulse shape (just a trapezoid)
for (i=0; i < 4000; i++)
{
oPulse_Cal1.asArbSqShape[i].flAbs = 0.01*i;
oPulse_Cal1.asArbSqShape[i].flPha = 0.0;
placeholder[i] = 0.01*i;
dNormalizedAmplitudeIntegral1 += placeholder[i];
}
oPulse_Cal1.dNormalizedAmplitudeIntegral = dNormalizedAmplitudeIntegral1;
I get the linking error:
CESTiPAT_OffsetSeriesd_CEST.obj : error LNK2001: unresolved external symbol "public: static struct sSampleTag * stPulse_Cal::asArbSqShape" (?asArbSqShape@stPulse_Cal@@2PAUsSampleTag@@A)
CESTiPAT_OffsetSeriesd_SpecialPulses.obj : error LNK2001: unresolved external symbol "public: static struct sSampleTag * stPulse_Cal::asArbSqShape" (?asArbSqShape@stPulse_Cal@@2PAUsSampleTag@@A)
\n4\x86\prod/bin/CESTiPAT_OffsetSeriesd.dll : fatal error LNK1120: 1 unresolved externals
make: *** [\n4\x86\prod/bin/CESTiPAT_OffsetSeriesd.dll] Error 96