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

时间:2012-05-06 20:08:38

标签: c++ map

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;
}

1 个答案:

答案 0 :(得分:5)

priority是指向const映射的指针,但operator []不能与const associative containers一起使用。