2015-11-02 61 views
0

我需要幫助瞭解如何調用地圖內部類的成員函數。地圖,類,成員函數

基本上我有一個包含一個對象的地圖,我試圖通過我不斷收到我無法處理的編譯器錯誤來調用它的一個成員函數。 下面是我當前擁有的函數調用代碼示例。

map<int, DailyReport> statContainer;  
for (auto x : statContainer) 
    { 
     if (x.first < yearAfter && x.first > year) 
     { 

      daycounter += 1; 
      fullYearHtemp += x.second.getHighTemp; 
      fullYearLtemp += x.second.getLowTemp; 
      fullYearPercip += x.second.getPercip; 
     } 
    } 

這可能嗎?我是否全都錯了?

編輯:getHighTemp,getLowTemp和getPercip都是類DailyReport的成員函數。當DailyReport對象位於地圖內時,我需要訪問這些函數。

+0

是'getHeightTemp','getLowPercent'等成員或成員函數? –

+0

抱歉,未能澄清,它們是成員函數。 – Animental

回答

1

應該是x.second.getHighTemp();(注意括號)?因爲getHighTemp()是一個成員函數。

+0

哇,難以置信,我花了最後一個半小時在網上搜索,盯着它只是爲了最終放棄並來到這裏問我的第一個問題,因爲它是一個值得明確表達的東西。啊。 – Animental

0

看起來你想打電話給那些爲成員函數,所以你需要追加()他們的名字,像:

map<int, DailyReport> statContainer; 
for (auto x : statContainer) 
    { 
     if (x.first < yearAfter && x.first > year) 
     { 

      daycounter += 1; 
      fullYearHtemp += x.second.getHighTemp(); 
      fullYearLtemp += x.second.getLowTemp(); 
      fullYearPercip += x.second.getPercip(); 
     } 
    }