C++ 错误 C2064:术语不计算为采用 0 个参数的函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6561134/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 20:21:29  来源:igfitidea点击:

error C2064: term does not evaluate to a function taking 0 arguments

c++pointersmap

提问by GoldenLee

everyone! I maintain a group of channel data in a map container, from which an individual channel data can be accessed by its channle name. With regards to this, I write a simple function GetIRChannelData(please see the following code). When compliing, the statement pusIRChannelData = cit->second();throwed an error, which read

每个人!我在地图容器中维护了一组频道数据,从中可以通过其频道名称访问单个频道数据。关于这个,我写了一个简单的函数GetIRChannelData(请看下面的代码)。编译时,该语句抛出pusIRChannelData = cit->second();一个错误,其中读取

error C2064: term does not evaluate to a function taking 0 arguments

All the function to do is nothing but to search for a given channel name/ID in the map container, and assign it data pointer to a temporal pointer if found. Would you please show me what's wrong?

所有要做的功能就是在地图容器中搜索给定的频道名称/ID,如果找到,则将数据指针分配给时间指针。你能告诉我有什么问题吗?

const Array2D<unsigned short>* GetIRChannelData(std::string sChannelName) const
{   
    const Array2D<unsigned short>* pusIRChannelData = NULL;

    for (std::map<std::string, Array2D<unsigned short>* >::const_iterator cit =    m_usIRDataPool.begin(); cit != m_usIRDataPool.end(); ++cit) 
    {   
        std::string sKey = cit->first; 

        if (sKey == sChannelName)
        {   
           pusIRChannelData = cit->second(); // Error occurred on this line
           break;
        }
    }

    return pusIRChannelData;
}

回答by Dennis Zickefoose

The error message is pretty clear... you call a function that doesn't exist. map::iteratorpoints to a std::pair, which has two member objects, firstand second. Note that these are not functions. Remove the ()from the line in question and the error should go away.

错误消息非常清楚……您调用了一个不存在的函数。 map::iterator指向 a std::pair,它有两个成员对象,firstsecond。请注意,这些不是函数。()从有问题的行中删除 ,错误应该消失。

回答by geekosaur

It looks like cit->seconddoesn't identify a function pointer. The definition of your iterator claims it's a pointer to (Array2D<unsigned short>); pusIRChannelDatais an (Array2D *), so you probably want cit->secondinstead of cit->second()(which tries to invoke your (Array2D *)as a function).

看起来cit->second没有识别函数指针。您的迭代器的定义声称它是一个指向(Array2D<unsigned short>); pusIRChannelData是一个(Array2D *),所以你可能想要cit->second而不是cit->second()(它试图将你的(Array2D *)作为函数调用)。