我对以下代码感到困惑,为什么它无法成功编译?
class Test {
public:
int GetValue( int key ) const
{
return testMap[key];
}
map<const int, const int> testMap;
};
Run Code Online (Sandbox Code Playgroud)
始终存在编译错误:
error C2678: binary '[': no ??operator found which takes "const std :: map <_Kty,_Ty>" type of the left operand operator (or there is no acceptable conversion).
Run Code Online (Sandbox Code Playgroud)
我试图将const限定符放在任何地方,但它仍然无法通过.你能告诉我为什么吗?