I have a class MySeqBuildBlockModule that I am inheriting from: public SeqBuildBlock.
Other than constructor and destructor, this class MySeqBuildBlockModule has a method: prep.
class MySeqBuildBlockModule: public SeqBuildBlock
{
friendclass SeqBuildBlockIRns;
public:
MySeqBuildBlockModule (SBBList* pSBBList0, long TI1_In, long TI2_In) // more arguements in this constructor of derived class
: SeqBuildBlock (pSBBList0)
{
TI1 = TI1_In; //in us
TI2 = TI2_In; //in us
pSBBList2 = pSBBList0;
//SeqBuildBlockIRns myIRns_3(pSBBList2); //Defined in libSBB.h
}
//~MySeqBuildBlockModule(){}
virtualbool prep (MrProt* pMrProt, SeqLim* pSeqLim, SeqExpo* pSeqExpo);
virtualbool run (MrProt* pMrProt, SeqLim* pSeqLim, SeqExpo* pSeqExpo, sSLICE_POS* pSLC);
protected:
private:
long TI1; //in us
long TI2; //in us
SBBList* pSBBList2;
SeqBuildBlockIRns myIRns_3(pSBBList2); // Line 106
};
1 2 3 4 5 6 7 8 9 10 11 12
bool MySeqBuildBlockModule::prep(MrProt* pMrProt, SeqLim* pSeqLim, SeqExpo* pSeqExpo)
{
NLS_STATUS lStatus;
double dEnergyAllSBBs_DK = myIRns_3.getEnergyPerRequest(); //Line 113
// Now we prepare:
lStatus = pSBBList->prepSBBAll(pMrProt, pSeqLim, pSeqExpo, &dEnergyAllSBBs_DK); // Line 116
if (lStatus ) {
cout << "DK: An error has occurred while preparing SBBs"<< endl;
}
return lStatus;
}
I would have like to intiantiate an object "myIRns_3" of a class defined in third party library
SeqBuildBlockIRns myIRns_3(pSBBList2);
and would like to access it from the prep function as: double dEnergyAllSBBs_DK = myIRns_3.getEnergyPerRequest();
I tried to instantiate following in either private section or in constructor; but w/o any success: SeqBuildBlockIRns myIRns_3(pSBBList2);
ERRORS encountered:
When I tried to do it inside the constructor, I get the following errors:
1 2 3 4
MySBBModule.h(113) : error C2065: 'myIRns_3' : undeclared identifier
MySBBModule.h(113) : error C2228: left of '.getEnergyPerRequest' must have class/struct/union type
MySBBModule.h(116) : error C2065: 'pSBBList' : undeclared identifier
MySBBModule.h(116) : error C2227: left of '->prepSBBAll' must point to class/struct/union
When I tried to do it in private section, I get the following errors:
1 2 3 4
MySBBModule.h(106) : error C2061: syntax error : identifier 'pSBBList2'
MySBBModule.h(113) : error C2228: left of '.getEnergyPerRequest' must have class/struct/union type
MySBBModule.h(116) : error C2065: 'pSBBList' : undeclared identifier
MySBBModule.h(116) : error C2227: left of '->prepSBBAll' must point to class/struct/union
PS: I have marked the line no in the code that I am posting.
private:
// ...
SeqBuildBlockIRns myIRns_3(pSBBList2); // Line 106
You can't invoke the constructor like that in a class definition. You need to simply declare the data member here, and then in the constructor(s) use the initialisation list to specify the argument that gets passed to the SeqBuildBlockIRns constructor.
SeqBuildBlockIRns myIRns_3;
rather than SeqBuildBlockIRns myIRns_3(pSBBList2);
2) then modified it in the constructor with the argument pSBBList2:
1 2 3 4
MySeqBuildBlockModule (SBBList* pSBBList0, long TI1_In, long TI2_In) // more arguements in this constructor of derived class
: SeqBuildBlock (pSBBList0),
myIRns_3(pSBBList0) // <- construct
{ }