2014-03-07 154 views
0

我有一個類MySeqBuildBlockModule,我繼承自:public SeqBuildBlock。 除了構造函數和析構函數,這個類MySeqBuildBlockModule有一個方法:prep在另一個類中初始化一個類的對象

class MySeqBuildBlockModule: public SeqBuildBlock 
{ 
    friend class 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(){} 
     virtual bool prep (MrProt* pMrProt, SeqLim* pSeqLim, SeqExpo* pSeqExpo); 
     virtual bool 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 
}; 

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

我會喜歡intiantiate在第三方庫

SeqBuildBlockIRns myIRns_3(pSBBList2); 

定義一個類的對象「myIRns_3」,並想從準備函數訪問它:

double dEnergyAllSBBs_DK = myIRns_3.getEnergyPerRequest(); 

我試圖在私有部分或構造函數中實例化以下內容;但W/O任何成功:

SeqBuildBlockIRns myIRns_3(pSBBList2); 

錯誤遇到:

當我試圖做到這一點在構造函數中,我得到以下錯誤:

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 

當我試圖做私人部分,我得到以下錯誤:

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:我有在我發佈的代碼中標記爲

任何幫助,將不勝感激。 問候, DK

回答

0

你的問題是,下面聲明功能

SeqBuildBlockIRns myIRns_3(pSBBList2); 

你想要做什麼是聲明一個成員:

SeqBuildBlockIRns myIRns_3; 

,然後在構造函數構造它與參數pSBBList2

MySeqBuildBlockModule (SBBList* pSBBList0, long TI1_In, long TI2_In) // more arguements in this constructor of derived class 
: SeqBuildBlock (pSBBList0), 
    myIRns_3(pSBBList2) // <- construct 
{ } 
+0

原因,我不能這樣做:SeqBuildBlockIRns myIRns_3;是因爲在第三方頭文件SeqBuildBlockIRns(SBBList *)中只定義了一個構造函數;由於我無權訪問CPP文件,因此我無法修改其構造函數。 –

+0

這與*聲明該類型的成員*有什麼關係?你*瞭解*以上語法在C++中的含義? – Nim

+0

謝謝Nim,它工作。感謝您澄清我的困惑。每當我聲明成員,我總是初始化它,因爲它給我錯誤:SeqBuildBlockIRns myIRns_3(pSBBList2); –