c++ - 为什么 c++ 告诉我没有 [] 与我传入的类型匹配?

标签 c++ dictionary

static const map<const Type*, int>* priority;

其中 Type 是我自己的特殊类。

初始化(为什么c++要求这个我不知道,auto甚至不起作用)

const map<const Type*, int, less<const Type*>, allocator<pair<const Type* const, int>>>* ToolProperty::priority
= new map<const Type*, int, less<const Type*>, allocator<pair<const Type* const, int>>>();

最后,尝试使用它(它告诉我我传递了错误的类型)

static void setPriority(const Type* type, int newPriority)
{
    (*priority)[type] = newPriority;
}

最佳答案

priority 是指向 const 映射的指针,但运算符[] 不能与 const 关联容器一起使用。

关于c++ - 为什么 c++ 告诉我没有 [] 与我传入的类型匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10473860/

相关文章:

c++ - 将对象从派生对象转换为基础对象,然后再返回

c++ - boost::rational - 防止默认减少(即 2/2 到 1/1)?

c++ - 超高性能C/C++ HashMap (表、字典)

c++ - 计算定点数的 sin() 和 cos() 的简单三角算法

c++ - C++ 中的运算符重载和多态性

c++ - 如何为 random_shuffle 编写 range-v3 Action ?

python - 将字典转换为可以转换的 float

python - 根据数据帧的列在 python 中创建字典

python - 使用关键字解包格式化 defaultdict **

python - 打开文本文件并在 Python 中获取冒号后面的数据