私のコードはもともと次のようなものでした:
int SomeObject::operator[]( const string& key ) const
{
return ( *m_Map )[ key ];
}
int SomeObject::operator()( const string& key ) const
{
return ( *m_Map2 )[ key ];
}
これらのマップには両方とも、次の署名がありました。
std::map< std::string, int >
そして、明示的なヒープ割り当てを実際に必要としないSTLコンテナーについて何かを読みました(つまりstd::map< ... >* map = new std::map< ... >
、それは私がしていたことです)。
マップをスタック割り当てに変更し、ポインター逆参照を削除するとすぐに、次のようになります。
int SomeObject::operator[]( const string& key ) const
{
return m_Map[ key ];
}
int SomeObject::operator()( const string& key ) const
{
return m_Map2[ key ];
}
コンパイラは、次のエラーで不平を言います (両方のマップに対して):
Error 1 error C2678: binary '[' : no operator found which takes a left-hand operand of type 'const std::map<_Kty,_Ty>' (or there is no acceptable conversion)
ワット。