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/