地图,类,成员函数

时间:2015-11-02 02:46:49

标签: c++ class dictionary member-functions

我需要帮助弄清楚如何调用一个类在地图中的成员函数。

基本上我有一个包含对象的地图,我试图通过我不能处理的编译器错误来调用它的一个成员函数。 这是我目前有函数调用的代码示例。

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对象位于地图内部时访问这些函数。

2 个答案:

答案 0 :(得分:1)

这应该是x.second.getHighTemp();(注意括号)?因为getHighTemp()是成员函数。

答案 1 :(得分: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();
        }
    }
相关问题