c++ - 在结构图上使用 find(),得到 "has no member named XXX"

标签 c++ dictionary struct

我定义了一个结构,使用 unsigned long long int 作为键来存储映射中的结构。 我有另一个函数可以在映射中找到结构并对结构进行一些修改。

但是我得到了这样的错误:

‘struct std::_Rb_tree_iterator<std::pair<const long long unsigned int, sStatics> >’ has no member named Latency

谁能告诉我错误是从哪里来的? 以下是我的代码结构:

嗯:

#include <map>

struct sStatics;
extern std::map<unsigned long long int, sStatics>  wsmStaticsMap;

A.cpp:

#include <map>

std::map<unsigned long long int, sStatics>  wsmStaticsMap;
struct sStatics
{
    std::string atcs;
    uint32_t Latency;
    std::vector<unsigned long int> lostWSM;
    unsigned long int wrongOrderCount;
};

static void function_statics(){

    std::map<unsigned long long int,sStatics>::iterator it;
    it = wsmStaticsMap.find(atcs);
    if (it != wsmStaticsMap.end()){
        it->Latency++;
    }

}

最佳答案

你必须写(it->second).Latency。它返回一个键值对。您需要先选择值,然后选择其中的属性。 您可以查看 reference

关于c++ - 在结构图上使用 find(),得到 "has no member named XXX",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32494166/

相关文章:

c - 在 C 中交换结构中的两个数组元素

c - 如何使用 C 中的整数对带有字符串的结构进行排序?

c++ - 我可以停止 GCC 将标准库名称包含到全局 namespace 中吗?

python-3.x - Python字典图matplotlib

python-3.x - 当 Python 映射函数中两个参数具有不同长度的列表时会发生什么?

c - 链表和内存地址

C++ 位操作

c++ - 值初始化c++

c++ - 添加日期时文件不输出

c - 在字典中查找单词 C 编程