【发布时间】:2011-09-27 12:23:11
【问题描述】:
大家!
我在地图容器中维护一组通道数据,可以通过其通道名称访问单个通道数据。关于这个,我写了一个简单的函数GetIRChannelData(请看下面的代码)。编译时,pusIRChannelData = cit->second(); 语句抛出错误,内容为
error C2064: term does not evaluate to a function taking 0 arguments
要做的所有功能就是在地图容器中搜索给定的频道名称/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;
}
【问题讨论】:
-
有什么特殊原因你不使用
std::map的find方法而不是循环遍历所有元素来寻找密钥? -
附带说明,类型别名确实有助于使代码更具可读性:
typedef std::map<...> DataPool; for (DataPool::const_iterator ...。