我只需要一个从一个浮动对象到另一个浮动对象的哈希图。应该很简单,不是吗?编译器只是不接受它:
声明:
unordered_map<float, float> m_mffPhotoPeakMap;
用途:
float CProductSpecs::AddToMap(float fEnergy, float returnedValue) const
{
auto pair = make_pair(fEnergy, returnedValue);
m_mffPhotoPeakMap.insert(pair); // Error! (First attempt)
m_mffPhotoPeakMap[fEnergy] = returnedValue; // Error! (Second attempt)
return returnedValue;
}
错误信息(第一次尝试:)>]
Severity Code Description Project File Line Suppression State Error C2663 'std::_Hash<std::_Umap_traits<_Kty,_Ty,std::_Uhash_compare<_Kty,_Hasher,_Keyeq>,_Alloc,false>>::insert': 6 overloads have no legal conversion for 'this' pointer
错误消息(第二次尝试):
Severity Code Description Project File Line Suppression State Error C2678 binary '[': no operator found which takes a left-hand operand of type 'const std::unordered_map<float,float,std::hash<float>,std::equal_to<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>' (or there is no acceptable conversion)
错误消息对我来说没有意义-语法似乎正确。谁能告诉我我做错了吗?
谢谢!艾伦
我只需要一个从一个浮动对象到另一个浮动对象的哈希图。应该很简单,不是吗?编译器只是不接受它:声明:unordered_map
您在const
成员函数中,试图对成员变量进行突变。
该函数被声明为常量非静态成员函数,